• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lmc-eu / matej-client-php / 7527331519

15 Jan 2024 10:11AM UTC coverage: 100.0%. Remained the same
7527331519

Pull #135

github

web-flow
Merge 117257645 into 9666a6254
Pull Request #135: Update to new coding standard

20 of 21 new or added lines in 5 files covered. (95.24%)

400 existing lines in 23 files now uncovered.

758 of 758 relevant lines covered (100.0%)

18.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Model/Command/ItemsFilteringTrait.php
1
<?php declare(strict_types=1);
2

3
namespace Lmc\Matej\Model\Command;
4

5
use Lmc\Matej\Model\Assertion;
6

7
trait ItemsFilteringTrait
8
{
9
    /** @var string */
10
    protected $filterOperator = 'and';
11
    /** @var string[] */
12
    private $filters;
13
    /** @var string[] */
14
    private $responseProperties;
15
    /** @var Boost[] */
16
    private $boosts = [];
17

18
    /**
19
     * Add a filter to already added filters (including the default filter).
20
     */
21
    public function addFilter(string $filter): self
22
    {
UNCOV
23
        if ($this->filters === null) {
8✔
UNCOV
24
            $this->filters = [];
8✔
25
        }
UNCOV
26
        $this->filters[] = $filter;
8✔
27

UNCOV
28
        return $this;
8✔
29
    }
30

31
    /**
32
     * Overwrite all filters by custom one. Note this will override also the default filter.
33
     */
34
    public function setFilters(array $filters): self
35
    {
UNCOV
36
        Assertion::allString($filters);
16✔
37

UNCOV
38
        $this->filters = $filters;
16✔
39

UNCOV
40
        return $this;
16✔
41
    }
42

43
    /**
44
     * Add another response property you want returned. item_id is always returned by Matej.
45
     */
46
    public function addResponseProperty(string $property): self
47
    {
UNCOV
48
        Assertion::typeIdentifier($property);
16✔
49

UNCOV
50
        if ($this->responseProperties === null) {
16✔
UNCOV
51
            $this->responseProperties = [];
16✔
52
        }
UNCOV
53
        $this->responseProperties[] = $property;
16✔
54

UNCOV
55
        return $this;
16✔
56
    }
57

58
    /**
59
     * Set all response properties you want returned. item_id is always returned by Matej, even when you don't specify
60
     * it.
61
     *
62
     * @param string[] $properties
63
     */
64
    public function setResponseProperties(array $properties): self
65
    {
UNCOV
66
        Assertion::allTypeIdentifier($properties);
8✔
67

UNCOV
68
        $this->responseProperties = $properties;
8✔
69

UNCOV
70
        return $this;
8✔
71
    }
72

73
    /**
74
     * Add a boost rule to already added rules.
75
     */
76
    public function addBoost(Boost $boost): self
77
    {
UNCOV
78
        $this->boosts[] = $boost;
16✔
79

UNCOV
80
        return $this;
16✔
81
    }
82

83
    /**
84
     * Set boosts. Removes all previously set rules.
85
     */
86
    public function setBoosts(array $boosts): self
87
    {
UNCOV
88
        $this->boosts = $boosts;
16✔
89

UNCOV
90
        return $this;
16✔
91
    }
92

93
    protected function assembleFiltersString(): string
94
    {
UNCOV
95
        return implode(' ' . $this->filterOperator . ' ', $this->filters);
16✔
96
    }
97

98
    protected function getSerializedBoosts(): array
99
    {
UNCOV
100
        return array_map(
16✔
UNCOV
101
            static function (Boost $boost) {
12✔
UNCOV
102
                return $boost->jsonSerialize();
16✔
UNCOV
103
            },
16✔
UNCOV
104
            $this->boosts
16✔
UNCOV
105
        );
12✔
106
    }
107

108
    protected function getItemsFilterParameters(): array
109
    {
UNCOV
110
        $parameters = [];
52✔
111

UNCOV
112
        if (!empty($this->boosts)) {
52✔
UNCOV
113
            $parameters['boost_rules'] = $this->getSerializedBoosts();
16✔
114
        }
115

UNCOV
116
        if ($this->filters !== null) {
52✔
UNCOV
117
            $parameters['filter'] = $this->assembleFiltersString();
16✔
118
        }
119

UNCOV
120
        if ($this->responseProperties !== null) {
52✔
UNCOV
121
            $parameters['properties'] = $this->responseProperties;
16✔
122
        }
123

UNCOV
124
        return $parameters;
52✔
125
    }
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc