| Conditions | 29 |
| Paths | 14 |
| Total Lines | 61 |
| Code Lines | 31 |
| 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 |
||
| 70 | public function find(string $workspaceId, string $userId, array $params = []): array |
||
| 71 | { |
||
| 72 | if (isset($params['description']) && !is_string($params['description'])) { |
||
| 73 | throw new ClockifyException('Invalid "description" parameter'); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (isset($params['start']) && !is_string($params['start'])) { |
||
| 77 | throw new ClockifyException('Invalid "start" parameter'); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (isset($params['end']) && !is_string($params['end'])) { |
||
| 81 | throw new ClockifyException('Invalid "end" parameter'); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (isset($params['project']) && !is_string($params['project'])) { |
||
| 85 | throw new ClockifyException('Invalid "project" parameter'); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (isset($params['task']) && !is_string($params['task'])) { |
||
| 89 | throw new ClockifyException('Invalid "task" parameter'); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (isset($params['tags']) && !is_array($params['tags'])) { |
||
| 93 | throw new ClockifyException('Invalid "tags" parameter'); |
||
| 94 | } |
||
| 95 | |||
| 96 | if (isset($params['project-required']) && !is_bool($params['project-required'])) { |
||
| 97 | throw new ClockifyException('Invalid "project-required" parameter'); |
||
| 98 | } |
||
| 99 | |||
| 100 | if (isset($params['task-required']) && !is_bool($params['task-required'])) { |
||
| 101 | throw new ClockifyException('Invalid "task-required" parameter'); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (isset($params['consider-duration-format']) && !is_bool($params['consider-duration-format'])) { |
||
| 105 | throw new ClockifyException('Invalid "consider-duration-format" parameter'); |
||
| 106 | } |
||
| 107 | |||
| 108 | if (isset($params['hydrated']) && !is_bool($params['hydrated'])) { |
||
| 109 | throw new ClockifyException('Invalid "hydrated" parameter'); |
||
| 110 | } |
||
| 111 | |||
| 112 | if (isset($params['in-progress']) && !is_bool($params['in-progress'])) { |
||
| 113 | throw new ClockifyException('Invalid "in-progress" parameter'); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (isset($params['page']) && (!is_int($params['page']) || $params['page'] < 1)) { |
||
| 117 | throw new ClockifyException('Invalid "page" parameter'); |
||
| 118 | } |
||
| 119 | |||
| 120 | if (isset($params['page-size']) && (!is_int($params['page-size']) || $params['page-size'] < 1)) { |
||
| 121 | throw new ClockifyException('Invalid "page-size" parameter'); |
||
| 122 | } |
||
| 123 | |||
| 124 | $data = $this->http->get("/workspaces/$workspaceId/user/$userId/time-entries", $params); |
||
| 125 | |||
| 126 | return array_map( |
||
| 127 | static function(array $timeEntry): TimeEntryDtoImpl { |
||
| 128 | return TimeEntryDtoImpl::fromArray($timeEntry); |
||
| 129 | }, |
||
| 130 | $data |
||
| 131 | ); |
||
| 134 |