| Conditions | 3 |
| Paths | 2 |
| Total Lines | 64 |
| Code Lines | 46 |
| 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 |
||
| 103 | final public static function findAll(Api\Client $client, array $criteria = []) : Api\Collection |
||
|
|
|||
| 104 | { |
||
| 105 | $filters = [ |
||
| 106 | 'format' => [ |
||
| 107 | [ |
||
| 108 | 'in', |
||
| 109 | [ |
||
| 110 | 'comic', |
||
| 111 | 'hardcover', |
||
| 112 | 'trade paperback', |
||
| 113 | 'magazine', |
||
| 114 | 'digest', |
||
| 115 | 'graphic novel', |
||
| 116 | 'digital comic', |
||
| 117 | 'infinite comic', |
||
| 118 | ] |
||
| 119 | ], |
||
| 120 | ], |
||
| 121 | 'formatType' => [['in', ['comic', 'collection']]], |
||
| 122 | 'noVariants' => [['bool'], ['bool-convert']], |
||
| 123 | 'dateDescriptor' => [['in', ['lastWeek', 'thisWeek', 'nextWeek', 'thisMonth']]], |
||
| 124 | 'fromDate' => [['date', true]], |
||
| 125 | 'toDate' => [['date', true]], |
||
| 126 | 'hasDigitalIssue' => [['bool'], ['bool-convert']], |
||
| 127 | 'modifiedSince' => [['date', true], ['date-format', 'c']], |
||
| 128 | 'creators' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 129 | 'characters' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 130 | 'series' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 131 | 'events' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 132 | 'stories' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 133 | 'sharedAppearances' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 134 | 'collaborators' => [['ofScalars', [['uint']]], ['implode', ',']], |
||
| 135 | 'orderBy' => [ |
||
| 136 | [ |
||
| 137 | 'in', |
||
| 138 | [ |
||
| 139 | 'focDate', |
||
| 140 | 'onsaleDate', |
||
| 141 | 'title', |
||
| 142 | 'issueNumber', |
||
| 143 | 'modified', |
||
| 144 | '-focDate', |
||
| 145 | '-onsaleDate', |
||
| 146 | '-title', |
||
| 147 | '-issueNumber', |
||
| 148 | '-modified', |
||
| 149 | ], |
||
| 150 | ] |
||
| 151 | ], |
||
| 152 | |||
| 153 | ]; |
||
| 154 | |||
| 155 | list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria); |
||
| 156 | Util::ensure(true, $success, $error); |
||
| 157 | |||
| 158 | $toDate = Util\Arrays::get($filteredCriteria, 'toDate'); |
||
| 159 | $fromDate = Util\Arrays::get($filteredCriteria, 'fromDate'); |
||
| 160 | if ($toDate !== null && $fromDate !== null) { |
||
| 161 | unset($filteredCriteria['toDate'], $filteredCriteria['fromDate']); |
||
| 162 | $filteredCriteria['dateRange'] = "{$fromDate->format('c')},{$toDate->format('c')}"; |
||
| 163 | } |
||
| 164 | |||
| 165 | return new Api\Collection($client, self::API_RESOURCE, $filteredCriteria); |
||
| 166 | } |
||
| 167 | } |
||
| 168 |