| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 42 |
| 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 |
||
| 93 | public function testGetDataAdvancedBaseCase() |
||
| 94 | { |
||
| 95 | $queryFilter = new QueryFilter(Response::class); |
||
| 96 | |||
| 97 | $config = new BaseConfig(); |
||
| 98 | $request = new Request(new HttpRequest([ |
||
| 99 | 'limit' => 100, |
||
| 100 | 'page'=> 3, |
||
| 101 | 'filter' => [ |
||
| 102 | [ |
||
| 103 | 'field' => 'c.hell', |
||
| 104 | 'type' => 'eq', |
||
| 105 | 'val' => 'the road to hell', |
||
| 106 | ], |
||
| 107 | [ |
||
| 108 | 'field' => 'c.heaven', |
||
| 109 | 'type' => 'like', |
||
| 110 | 'val' => 'the road to heaven', |
||
| 111 | ], |
||
| 112 | ], |
||
| 113 | 'sortby' => 'c.id', |
||
| 114 | 'sortdir' => 'asc', |
||
| 115 | 'simple' => '0', |
||
| 116 | ])); |
||
| 117 | $config->setRequest($request); |
||
| 118 | $config->setSearchAllowedCols(['c.hell', 'c.heaven']); |
||
| 119 | $config->setSortCols(['c.id']); |
||
| 120 | |||
| 121 | $config->setRepositoryCallback(function(QueryFilterArgs $args) { |
||
| 122 | self::assertSame(100, $args->getLimit()); |
||
| 123 | self::assertSame(200, $args->getOffset()); |
||
| 124 | self::assertEquals([ |
||
| 125 | 'c.hell' => [ |
||
| 126 | 'type' => 'eq', |
||
| 127 | 'val' => 'the road to hell' |
||
| 128 | ], |
||
| 129 | 'c.heaven' => [ |
||
| 130 | 'type' => 'like', |
||
| 131 | 'val' => 'the%road%to%heaven' |
||
| 132 | ], |
||
| 133 | ], $args->getSearchBy()); |
||
| 134 | self::assertEquals([ |
||
| 135 | 'c.id' => 'asc', |
||
| 136 | ], $args->getSortBy()); |
||
| 137 | |||
| 138 | return new QueryResult([ |
||
| 139 | ["dummy"], |
||
| 140 | ["wammy"], |
||
| 141 | ], 1000); |
||
| 142 | }); |
||
| 143 | $response = $queryFilter->getData($config); |
||
| 144 | self::assertEquals([ |
||
| 145 | ["dummy"], |
||
| 146 | ["wammy"], |
||
| 147 | ], $response->getData()); |
||
| 148 | self::assertSame(1000, $response->getMeta()['total_records']); |
||
| 149 | } |
||
| 151 |