| Conditions | 10 |
| Paths | 17 |
| Total Lines | 34 |
| 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 |
||
| 120 | protected static function getEntityIdsQuery(string $nameId, array $args): ActiveQuery |
||
| 121 | { |
||
| 122 | $conditions = []; |
||
| 123 | |||
| 124 | if (isset($args['owner'])) { |
||
| 125 | if (!is_string($args['owner']) || empty($args['owner'])) { |
||
| 126 | throw new InvalidArgumentException('Parameter owner must be a string.'); |
||
| 127 | } |
||
| 128 | $conditions['owner'] = $args['owner']; |
||
| 129 | |||
| 130 | if (isset($args['ownerId'])) { |
||
| 131 | if (!is_numeric($args['ownerId'])) { |
||
| 132 | throw new InvalidArgumentException('Parameter ownerId must be numeric.'); |
||
| 133 | } |
||
| 134 | $conditions['ownerId'] = $args['ownerId']; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | if (isset($args['ownerAttribute'])) { |
||
| 139 | if (!is_string($args['ownerAttribute']) || empty($args['ownerAttribute'])) { |
||
| 140 | throw new InvalidArgumentException('Parameter ownerAttribute must be a string.'); |
||
| 141 | } |
||
| 142 | $conditions['ownerAttribute'] = $args['ownerAttribute']; |
||
| 143 | } |
||
| 144 | |||
| 145 | $query = static::find() |
||
| 146 | ->select($nameId); |
||
| 147 | |||
| 148 | if (count($conditions) > 0) { |
||
| 149 | return $query->where($conditions); |
||
| 150 | } |
||
| 151 | |||
| 152 | return $query; |
||
| 153 | } |
||
| 154 | } |
||
| 155 |