GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Filter::like()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Soheilrt\AdobeConnectClient\Client;
4
5
use DateTime;
6
use DateTimeInterface;
7
use Soheilrt\AdobeConnectClient\Client\Contracts\ArrayableInterface;
8
use Soheilrt\AdobeConnectClient\Client\Helpers\StringCaseTransform as SCT;
9
use Soheilrt\AdobeConnectClient\Client\Helpers\ValueTransform as VT;
10
11
/**
12
 * Create valid filters using Fluent Interface.
13
 *
14
 * See {@link https://helpx.adobe.com/content/help/en/adobe-connect/webservices/filter-definition.html}
15
 */
16
class Filter implements ArrayableInterface
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $filters = [];
22
23
    /**
24
     * Prefix to use in filters to indicate it's filter.
25
     *
26
     * @var string
27
     */
28
    protected $prefix = 'filter';
29
30
    /**
31
     * Return a new Filter instance.
32
     *
33
     * @return Filter
34
     */
35
    public static function instance(): Filter
36
    {
37
        return new static();
38
    }
39
40
    /**
41
     * Returns if exactly matches.
42
     *
43
     * @param string $field The Field in camelCase
44
     * @param mixed  $value The Value to compare
45
     *
46
     * @return Filter Fluent Interface
47
     */
48
    public function equals($field, $value): Filter
49
    {
50
        $this->setFilter('', $field, $value);
51
52
        return $this;
53
    }
54
55
    /**
56
     * Set the Filter.
57
     *
58
     * @param string $operator
59
     * @param string $field
60
     * @param mixed  $value
61
     */
62
    protected function setFilter($operator, $field, $value): void
63
    {
64
        $filterName = $this->prefix
65
            . '-'
66
            . ($operator ? $operator . '-' : '')
67
            . SCT::toHyphen($field);
68
69
        $this->filters[$filterName] = VT::toString($value);
70
    }
71
72
    /**
73
     * Returns even if is not an exact match.
74
     *
75
     * @param string $field The Field in camelCase
76
     * @param mixed  $value The Value to compare
77
     *
78
     * @return Filter Fluent Interface
79
     */
80
    public function like($field, $value): Filter
81
    {
82
        $this->setFilter('like', $field, $value);
83
84
        return $this;
85
    }
86
87
    /**
88
     * Filters out or excludes.
89
     *
90
     * @param string $field The Field in camelCase
91
     * @param mixed  $value The Value to compare
92
     *
93
     * @return Filter Fluent Interface
94
     */
95
    public function out($field, $value): Filter
96
    {
97
        $this->setFilter('out', $field, $value);
98
99
        return $this;
100
    }
101
102
    /**
103
     * Limits the results to the number of rows specified.
104
     *
105
     * @param int $limit The limit rows
106
     *
107
     * @return Filter Fluent Interface
108
     */
109
    public function rows($limit): Filter
110
    {
111
        $this->setFilter('', 'rows', $limit);
112
113
        return $this;
114
    }
115
116
    /**
117
     * Starts the results at the index number specified.
118
     *
119
     * @param int $offset The initial index
120
     *
121
     * @return Filter Fluent Interface
122
     */
123
    public function start($offset): Filter
124
    {
125
        $this->setFilter('', 'start', $offset);
126
127
        return $this;
128
    }
129
130
    /**
131
     * Selects all items with a date after.
132
     *
133
     * @param string            $dateField The Date Field in camelCase
134
     * @param DateTimeInterface $date      The value to compare
135
     * @param bool              $inclusive Filter inclusive the date
136
     *
137
     * @return Filter Fluent Interface
138
     */
139
    public function dateAfter($dateField, DateTimeInterface $date, $inclusive = true): Filter
140
    {
141
        $this->setFilter(
142
            $inclusive ? 'gte' : 'gt',
143
            $dateField,
144
            $date->format(DateTime::W3C)
145
        );
146
147
        return $this;
148
    }
149
150
    /**
151
     * Selects all items with a date earlier.
152
     *
153
     * @param string            $dateField The Date Field in camelCase
154
     * @param DateTimeInterface $date      The value to compare
155
     * @param bool              $inclusive Filter inclusive the date
156
     *
157
     * @return Filter Fluent Interface
158
     */
159
    public function dateBefore($dateField, DateTimeInterface $date, $inclusive = true): Filter
160
    {
161
        $this->setFilter(
162
            $inclusive ? 'lte' : 'lt',
163
            $dateField,
164
            $date->format(DateTime::W3C)
165
        );
166
167
        return $this;
168
    }
169
170
    /**
171
     * Selects all principals that are members of a group, specified in a separate parameter.
172
     *
173
     * @param mixed $value The value to compare
174
     *
175
     * @return Filter Fluent Interface
176
     */
177
    public function isMember($value): Filter
178
    {
179
        $this->setFilter('', 'ismember', $value);
180
181
        return $this;
182
    }
183
184
    /**
185
     * Remove all filters using the Field.
186
     *
187
     * @param string $field The Field in camelCase
188
     *
189
     * @return Filter
190
     */
191
    public function removeField($field): Filter
192
    {
193
        $field = SCT::toHyphen($field);
194
        $this->filters = array_filter(
195
            $this->filters,
196
            static function ($filter) use ($field) {
197
                return mb_strpos($filter, $field) === false;
198
            },
199
            ARRAY_FILTER_USE_KEY
200
        );
201
202
        return $this;
203
    }
204
205
    /**
206
     * Retrieves all not null attributes in an associative array.
207
     *
208
     * The keys in hash style: Ex: is-member
209
     * The values as string
210
     *
211
     * @return string[]
212
     */
213
    public function toArray(): array
214
    {
215
        return $this->filters;
216
    }
217
}
218