Conditions | 17 |
Paths | 2250 |
Total Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
69 | public function buildApplyFilterUrl(UriInterface $uri, Filter $filter, $value = null): UriInterface |
||
70 | { |
||
71 | $uri = $this->pagerUriManager->buildPageUri($uri, 1); |
||
72 | $qs = query_string($uri); |
||
73 | $currentFilters = $qs->getParam($this->getOption(self::OPT_FILTER_QUERY_PARAM)) ?? []; |
||
74 | |||
75 | if ($filter instanceof CollectionFilter) { |
||
76 | $values = func_num_args() > 2 ? (array) $value : $filter->getValues(); |
||
77 | if ($filter->getSatisfiedBy() !== $this->getOption(self::OPT_DEFAULT_COLLECTION_SATISFIED_BY)) { |
||
78 | $values = [$filter->getSatisfiedBy() => $values]; |
||
79 | } |
||
80 | $values = $filter->isNegated() ? ['NOT' => $values] : $values; |
||
81 | $currentFilters[$filter->getField()] = $values; |
||
82 | } |
||
83 | |||
84 | if ($filter instanceof SimpleFilter) { |
||
85 | $value = func_num_args() > 2 ? $value : $filter->getValue(); |
||
86 | $currentFilters[$filter->getField()] = $filter->isNegated() ? ['NOT' => $value] : $value; |
||
87 | } |
||
88 | |||
89 | if ($filter instanceof RangeFilter) { |
||
90 | $value = func_num_args() > 2 ? (array) $value : [$filter->getLeft(), $filter->getRight()]; |
||
91 | $normalizedvalue = sprintf('[%s TO %s]', $value[0] ?? '*', $value[1] ?? '*'); |
||
92 | $currentFilters[$filter->getField()] = $filter->isNegated() ? ['NOT' => $normalizedvalue] : $normalizedvalue; |
||
93 | } |
||
94 | |||
95 | if ($filter instanceof StringMatchFilter) { |
||
96 | $value = func_num_args() > 2 ? $value : $filter->getValue(); |
||
97 | $normalizedvalue = [$filter->getOperator() => $value]; |
||
98 | $currentFilters[$filter->getField()] = $filter->isNegated() ? ['NOT' => $normalizedvalue] : $normalizedvalue; |
||
99 | } |
||
100 | |||
101 | if ($filter instanceof CompositeFilter) { |
||
102 | $parts = [$currentFilters[$filter->getField()] ?? []]; |
||
103 | foreach ($filter->getFilters() as $subFilter) { |
||
104 | $subFilterValue = (array) (query_string($this->buildApplyFilterUrl($uri, $subFilter))->getParam($this->getOption(self::OPT_FILTER_QUERY_PARAM), $subFilter->getField()) ?? []); |
||
105 | $subFilterValue = [$filter->getSatisfiedBy() => $subFilterValue]; |
||
106 | if ($filter->isNegated()) { |
||
107 | $subFilterValue = ['NOT' => $subFilterValue]; |
||
108 | } |
||
109 | $parts[] = $subFilterValue; |
||
110 | } |
||
111 | |||
112 | $currentFilters[$filter->getField()] = array_merge_recursive(...$parts); |
||
113 | } |
||
114 | |||
115 | $qs = $qs->withParam($this->getOption(self::OPT_FILTER_QUERY_PARAM), $currentFilters); |
||
116 | |||
117 | return $uri->withQuery((string) $qs->withRenderer(withoutNumericIndices())); |
||
118 | } |
||
119 | |||
144 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.