| Total Complexity | 40 |
| Total Lines | 118 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 0 |
Complex classes like TimeEntry often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TimeEntry, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class TimeEntry |
||
| 14 | { |
||
| 15 | private $http; |
||
| 16 | |||
| 17 | public function __construct(Client $http) |
||
| 20 | } |
||
| 21 | |||
| 22 | public function create(string $workspaceId, TimeEntryRequest $request): TimeEntryDtoImpl |
||
| 27 | } |
||
| 28 | |||
| 29 | public function createForUser(string $workspaceId, string $userId, TimeEntryRequest $request): TimeEntryDtoImpl |
||
| 30 | { |
||
| 31 | $data = $this->http->post("/workspaces/$workspaceId/user/$userId/time-entries", $request->toArray()); |
||
| 32 | |||
| 33 | return TimeEntryDtoImpl::fromArray($data); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function update(string $workspaceId, string $id, UpdateTimeEntryRequest $request): TimeEntryDtoImpl |
||
| 41 | } |
||
| 42 | |||
| 43 | public function entry(string $workspaceId, string $id, array $params = []): TimeEntryDtoImpl |
||
| 44 | { |
||
| 45 | if (isset($params['consider-duration-format']) && !is_bool($params['consider-duration-format'])) { |
||
| 46 | throw new ClockifyException('Invalid "consider-duration-format" parameter (should be a boolean value)'); |
||
| 47 | } |
||
| 48 | |||
| 49 | if (isset($params['hydrated']) && !is_bool($params['hydrated'])) { |
||
| 50 | throw new ClockifyException('Invalid "hydrated" parameter (should be a boolean value)'); |
||
| 51 | } |
||
| 52 | |||
| 53 | $data = $this->http->get("/workspaces/$workspaceId/time-entries/$id", $params); |
||
| 54 | |||
| 55 | return TimeEntryDtoImpl::fromArray($data); |
||
| 56 | } |
||
| 57 | |||
| 58 | public function delete(string $workspaceId, string $id): void |
||
| 61 | } |
||
| 62 | |||
| 63 | public function stopRunningTime(string $workspaceId, string $userId, StopTimeEntryRequest $request): TimeEntryDtoImpl |
||
| 64 | { |
||
| 65 | $data = $this->http->patch("/workspaces/$workspaceId/user/$userId/time-entries", $request->toArray()); |
||
| 66 | |||
| 67 | return TimeEntryDtoImpl::fromArray($data); |
||
| 68 | } |
||
| 69 | |||
| 70 | public function find(string $workspaceId, string $userId, array $params = []): array |
||
| 131 | ); |
||
| 132 | } |
||
| 134 |