| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| 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 |
||
| 90 | public function testAddOrderWithSort() |
||
| 91 | { |
||
| 92 | $request = new Request([ |
||
| 93 | 'sort' => 'name', |
||
| 94 | ]); |
||
| 95 | |||
| 96 | $requestStack = $this->getMockWithoutConstructor(RequestStack::class); |
||
| 97 | $requestStack |
||
| 98 | ->expects($this->atLeastOnce()) |
||
| 99 | ->method('getMasterRequest') |
||
| 100 | ->willReturn($request) |
||
| 101 | ; |
||
| 102 | $admin = $this->getMockWithoutConstructor(AdminInterface::class); |
||
| 103 | $action = $this->getMockWithoutConstructor(ActionInterface::class); |
||
| 104 | |||
| 105 | $configuration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
||
| 106 | |||
| 107 | $queryBuilder = $this->getMockWithoutConstructor(QueryBuilder::class); |
||
| 108 | $queryBuilder |
||
| 109 | ->expects($this->once()) |
||
| 110 | ->method('getRootAliases') |
||
| 111 | ->willReturn([ |
||
| 112 | 'entity', |
||
| 113 | ]) |
||
| 114 | ; |
||
| 115 | $queryBuilder |
||
| 116 | ->expects($this->once()) |
||
| 117 | ->method('addOrderBy') |
||
| 118 | ->with('entity.name', 'asc') |
||
| 119 | ; |
||
| 120 | |||
| 121 | $event = $this->getMockWithoutConstructor(DoctrineOrmFilterEvent::class); |
||
| 122 | $event |
||
| 123 | ->expects($this->once()) |
||
| 124 | ->method('getQueryBuilder') |
||
| 125 | ->willReturn($queryBuilder) |
||
| 126 | ; |
||
| 127 | $event |
||
| 128 | ->expects($this->once()) |
||
| 129 | ->method('getAdmin') |
||
| 130 | ->willReturn($admin) |
||
| 131 | ; |
||
| 132 | $admin |
||
| 133 | ->expects($this->once()) |
||
| 134 | ->method('getAction') |
||
| 135 | ->willReturn($action) |
||
| 136 | ; |
||
| 137 | $action |
||
| 138 | ->expects($this->once()) |
||
| 139 | ->method('getConfiguration') |
||
| 140 | ->willReturn($configuration) |
||
| 141 | ; |
||
| 142 | |||
| 143 | $subscriber = new ORMSubscriber($requestStack); |
||
| 144 | $subscriber->addOrder($event); |
||
| 145 | } |
||
| 146 | |||
| 202 |