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 |
||
72 | protected static function getEntityIdsQuery(string $nameId, array $args): ActiveQuery |
||
73 | { |
||
74 | $conditions = []; |
||
75 | |||
76 | if (isset($args['owner'])) { |
||
77 | if (!is_string($args['owner']) || empty($args['owner'])) { |
||
78 | throw new InvalidArgumentException('Parameter owner must be a string.'); |
||
79 | } |
||
80 | $conditions['owner'] = $args['owner']; |
||
81 | |||
82 | if (isset($args['ownerId'])) { |
||
83 | if (!is_numeric($args['ownerId'])) { |
||
84 | throw new InvalidArgumentException('Parameter ownerId must be numeric.'); |
||
85 | } |
||
86 | $conditions['ownerId'] = $args['ownerId']; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | if (isset($args['ownerAttribute'])) { |
||
91 | if (!is_string($args['ownerAttribute']) || empty($args['ownerAttribute'])) { |
||
92 | throw new InvalidArgumentException('Parameter ownerAttribute must be a string.'); |
||
93 | } |
||
94 | $conditions['ownerAttribute'] = $args['ownerAttribute']; |
||
95 | } |
||
96 | |||
97 | $query = static::find() |
||
98 | ->select($nameId); |
||
99 | |||
100 | if (count($conditions) > 0) { |
||
101 | return $query->where($conditions); |
||
102 | } |
||
103 | |||
104 | return $query; |
||
105 | } |
||
106 | } |
||
107 |