Conditions | 5 |
Paths | 16 |
Total Lines | 71 |
Code Lines | 48 |
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 |
||
44 | public function testFilterWillApplyFiltering(array $criteria): void |
||
45 | { |
||
46 | $fieldName = $criteria['field'] ?? 'testFieldName'; |
||
47 | $alias = $criteria['alias'] ?? null; |
||
48 | |||
49 | $mapping = [ |
||
50 | 'type' => 4 |
||
51 | ]; |
||
52 | |||
53 | $this->metadata->expects($this->once()) |
||
54 | ->method('hasField') |
||
55 | ->with($fieldName) |
||
56 | ->willReturn(true); |
||
57 | |||
58 | $this->metadata->expects($this->once()) |
||
59 | ->method('hasAssociation') |
||
60 | ->with($fieldName) |
||
61 | ->willReturn(true); |
||
62 | |||
63 | $this->metadata->expects($this->once()) |
||
64 | ->method('getAssociationMapping') |
||
65 | ->with($fieldName) |
||
66 | ->willReturn($mapping); |
||
67 | |||
68 | /** @var Expr|MockObject $expr */ |
||
69 | $expr = $this->createMock(Expr::class); |
||
70 | |||
71 | $this->queryBuilder->expects($this->once()) |
||
72 | ->method('expr') |
||
73 | ->willReturn($expr); |
||
74 | |||
75 | /** @var Expr\Comparison|MockObject $comparisonExpr */ |
||
76 | $comparisonExpr = $this->createMock(Expr\Comparison::class); |
||
77 | |||
78 | if (null === $alias) { |
||
79 | $alias = 'entity'; |
||
80 | $this->queryBuilder->expects($this->once()) |
||
81 | ->method('getRootAlias') |
||
82 | ->willReturn($alias); |
||
83 | } |
||
84 | |||
85 | $expressionString = $this->getExpressionString($fieldName, $alias, $criteria); |
||
86 | |||
87 | $expr->expects($this->once()) |
||
88 | ->method($this->expressionMethodName) |
||
89 | ->willReturn($comparisonExpr); |
||
90 | |||
91 | $comparisonExpr->expects($this->once()) |
||
92 | ->method('__toString') |
||
93 | ->willReturn($expressionString); |
||
94 | |||
95 | $methodName = (!isset($criteria['where']) || WhereType::AND === $criteria['where']) |
||
96 | ? 'andWhere' |
||
97 | : 'orWhere'; |
||
98 | |||
99 | $this->queryBuilder->expects($this->once())->method($methodName); |
||
100 | |||
101 | if (array_key_exists('value', $criteria)) { |
||
102 | $this->typecaster->expects($this->once()) |
||
103 | ->method('typecast') |
||
104 | ->with($this->metadata, $fieldName, $criteria['value']) |
||
105 | ->willReturn($criteria['value']); |
||
106 | |||
107 | $this->queryBuilder->expects($this->once()) |
||
108 | ->method('setParameter') |
||
109 | ->with($this->callback(static function ($argument) { |
||
110 | return is_string($argument); |
||
111 | }), $criteria['value']); |
||
112 | } |
||
113 | |||
114 | $this->filter->filter($this->queryBuilder, $this->metadata, $criteria); |
||
115 | } |
||
145 |