Conditions | 4 |
Paths | 8 |
Total Lines | 58 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
95 | public function testFilterWillApplyIsNotEqualFiltering(): void |
||
96 | { |
||
97 | $filter = new IsNotEqual($this->queryFilterManager, $this->typecaster); |
||
98 | |||
99 | $fieldName = 'FieldNameTest'; |
||
100 | $criteria = [ |
||
101 | 'field' => $fieldName, |
||
102 | 'alias' => 'test', |
||
103 | 'where' => WhereType::AND, |
||
104 | 'value' => 123, |
||
105 | 'format' => null, |
||
106 | ]; |
||
107 | |||
108 | $this->metadata->expects($this->once()) |
||
109 | ->method('hasField') |
||
110 | ->with($fieldName) |
||
111 | ->willReturn(true); |
||
112 | |||
113 | /** @var Expr|MockObject $expr */ |
||
114 | $expr = $this->createMock(Expr::class); |
||
115 | |||
116 | $this->queryBuilder->expects($this->once()) |
||
117 | ->method('expr') |
||
118 | ->willReturn($expr); |
||
119 | |||
120 | /** @var Expr\Comparison|MockObject $neq */ |
||
121 | $neq = $this->createMock(Expr\Comparison::class); |
||
122 | |||
123 | $isNotEqualString = $criteria['alias'] . '.' . $fieldName . '!=' . ':param_name'; |
||
124 | $expr->expects($this->once()) |
||
125 | ->method('neq') |
||
126 | ->with($criteria['alias'] . '.' . $fieldName, $this->stringStartsWith(':')) |
||
127 | ->willReturn($neq); |
||
128 | |||
129 | $neq->expects($this->once()) |
||
130 | ->method('__toString') |
||
131 | ->willReturn($isNotEqualString); |
||
132 | |||
133 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
134 | ? 'andWhere' |
||
135 | : 'orWhere'; |
||
136 | |||
137 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
138 | |||
139 | if (array_key_exists('value', $criteria)) { |
||
140 | $this->typecaster->expects($this->once()) |
||
|
|||
141 | ->method('typecast') |
||
142 | ->with($this->metadata, $fieldName, $criteria['value']) |
||
143 | ->willReturn($criteria['value']); |
||
144 | |||
145 | $this->queryBuilder->expects($this->once()) |
||
146 | ->method('setParameter') |
||
147 | ->with($this->callback(static function ($argument) { |
||
148 | return is_string($argument); |
||
149 | }), $criteria['value']); |
||
150 | } |
||
151 | |||
152 | $filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
153 | } |
||
155 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.