Conditions | 4 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 36 |
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 |
||
87 | public function testFilterWillApplyIsNotEqualFiltering(): void |
||
88 | { |
||
89 | $filter = new IsNotEqual($this->queryFilterManager); |
||
90 | |||
91 | $fieldName = 'FieldNameTest'; |
||
92 | $criteria = [ |
||
93 | 'field' => $fieldName, |
||
94 | 'alias' => 'test', |
||
95 | 'where' => WhereType::AND, |
||
96 | 'value' => 123, |
||
97 | 'format' => null, |
||
98 | ]; |
||
99 | |||
100 | $this->metadata->expects($this->once()) |
||
101 | ->method('hasField') |
||
102 | ->with($fieldName) |
||
103 | ->willReturn(true); |
||
104 | |||
105 | /** @var Expr|MockObject $expr */ |
||
106 | $expr = $this->createMock(Expr::class); |
||
107 | |||
108 | $this->queryBuilder->expects($this->once()) |
||
109 | ->method('expr') |
||
110 | ->willReturn($expr); |
||
111 | |||
112 | /** @var Expr\Comparison|MockObject $neq */ |
||
113 | $neq = $this->createMock(Expr\Comparison::class); |
||
114 | |||
115 | $isNotEqualString = $criteria['alias'] . '.' . $fieldName . '!=' . ':param_name'; |
||
116 | $expr->expects($this->once()) |
||
117 | ->method('neq') |
||
118 | ->with($criteria['alias'] . '.' . $fieldName, $this->stringStartsWith(':')) |
||
119 | ->willReturn($neq); |
||
120 | |||
121 | $neq->expects($this->once()) |
||
122 | ->method('__toString') |
||
123 | ->willReturn($isNotEqualString); |
||
124 | |||
125 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
126 | ? 'andWhere' |
||
127 | : 'orWhere'; |
||
128 | |||
129 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
130 | |||
131 | if (array_key_exists('value', $criteria)) { |
||
132 | $this->queryBuilder->expects($this->once()) |
||
133 | ->method('setParameter') |
||
134 | ->with($this->callback(static function ($argument) { |
||
135 | return is_string($argument); |
||
136 | }), $criteria['value']); |
||
137 | } |
||
138 | |||
139 | $filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
140 | } |
||
142 |