Conditions | 11 |
Paths | 5 |
Total Lines | 25 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
25 | public function tasks(string $workspaceId, string $projectId, array $params = []): array |
||
26 | { |
||
27 | if (isset($params['is-active']) && !is_bool($params['is-active'])) { |
||
28 | throw new ClockifyException('Invalid "is-active" parameter (should be a boolean value)'); |
||
29 | } |
||
30 | |||
31 | if (isset($params['name']) && empty($params['name'])) { |
||
32 | throw new ClockifyException('Invalid "name" parameter'); |
||
33 | } |
||
34 | |||
35 | if (isset($params['page']) && (!is_int($params['page']) || $params['page'] < 1)) { |
||
36 | throw new ClockifyException('Invalid "page" parameter'); |
||
37 | } |
||
38 | |||
39 | if (isset($params['page-size']) && (!is_int($params['page-size']) || $params['page-size'] < 1)) { |
||
40 | throw new ClockifyException('Invalid "page-size" parameter'); |
||
41 | } |
||
42 | |||
43 | $data = $this->http->get("/workspaces/$workspaceId/projects/$projectId/tasks", $params); |
||
44 | |||
45 | return array_map( |
||
46 | static function(array $task): TaskDto { |
||
47 | return TaskDto::fromArray($task); |
||
48 | }, |
||
49 | $data |
||
50 | ); |
||
60 |