Conditions | 4 |
Paths | 4 |
Total Lines | 87 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
86 | public function testFilterIsBetween(array $criteria): void |
||
87 | { |
||
88 | /** @var IsBetween&MockObject $filter */ |
||
89 | $filter = $this->getMockBuilder(IsBetween::class) |
||
90 | ->setConstructorArgs([$this->queryFilterManager, $this->typecaster, $this->paramNameGenerator]) |
||
91 | ->onlyMethods(['createParamName']) |
||
92 | ->getMock(); |
||
93 | |||
94 | $rootAlias = 'entity'; |
||
95 | $from = $criteria['from'] ?? ''; |
||
96 | $to = $criteria['to'] ?? ''; |
||
97 | $alias = $criteria['alias'] ?? 'entity'; |
||
98 | $fieldName = $criteria['field'] = $criteria['field'] ?? 'test'; |
||
99 | $formatType = $criteria['format'] ?? null; |
||
100 | |||
101 | $this->metadata->expects($this->once()) |
||
|
|||
102 | ->method('hasField') |
||
103 | ->with($fieldName) |
||
104 | ->willReturn(true); |
||
105 | |||
106 | if (empty($criteria['alias'])) { |
||
107 | $alias = $rootAlias; |
||
108 | |||
109 | $this->queryBuilder->expects($this->once()) |
||
110 | ->method('getRootAlias') |
||
111 | ->willReturn($rootAlias); |
||
112 | } |
||
113 | |||
114 | /** @var Expr&MockObject $expr */ |
||
115 | $expr = $this->createMock(Expr::class); |
||
116 | |||
117 | $this->queryBuilder->expects($this->once()) |
||
118 | ->method('expr') |
||
119 | ->willReturn($expr); |
||
120 | |||
121 | $fromParam = $alias . 'abc123'; |
||
122 | $toParam = $alias . 'zyx999'; |
||
123 | |||
124 | $filter->expects($this->exactly(2)) |
||
125 | ->method('createParamName') |
||
126 | ->withConsecutive( |
||
127 | ['from', $fieldName, $alias], |
||
128 | ['to', $fieldName, $alias] |
||
129 | )->willReturnOnConsecutiveCalls( |
||
130 | $fromParam, |
||
131 | $toParam |
||
132 | ); |
||
133 | |||
134 | $isBetween = $alias . '.' . $fieldName . ' BETWEEN ' . $fromParam . ' AND ' . $toParam; |
||
135 | $expr->expects($this->once()) |
||
136 | ->method('between') |
||
137 | ->with( |
||
138 | $alias . '.' . $fieldName, |
||
139 | ':' . $fromParam, |
||
140 | ':' . $toParam |
||
141 | )->willReturn( |
||
142 | $isBetween |
||
143 | ); |
||
144 | |||
145 | if (empty($criteria['where']) || WhereType::AND === $criteria['where']) { |
||
146 | $this->queryBuilder->expects($this->once()) |
||
147 | ->method('andWhere') |
||
148 | ->with($isBetween); |
||
149 | } else { |
||
150 | $this->queryBuilder->expects($this->once()) |
||
151 | ->method('orWhere') |
||
152 | ->with($isBetween); |
||
153 | } |
||
154 | |||
155 | $this->typecaster->expects($this->exactly(2)) |
||
156 | ->method('typecast') |
||
157 | ->withConsecutive( |
||
158 | [$this->metadata, $fieldName, $from, $formatType, []], |
||
159 | [$this->metadata, $fieldName, $to, $formatType, []], |
||
160 | )->willReturnOnConsecutiveCalls( |
||
161 | $from, |
||
162 | $to |
||
163 | ); |
||
164 | |||
165 | $this->queryBuilder->expects($this->exactly(2)) |
||
166 | ->method('setParameter') |
||
167 | ->withConsecutive( |
||
168 | [$fromParam, $from], |
||
169 | [$toParam, $to] |
||
170 | ); |
||
171 | |||
172 | $filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
173 | } |
||
214 |
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.