1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Marek\Toggable\Service\Dashboard; |
4
|
|
|
|
5
|
|
|
use Marek\Toggable\API\Http\Request\Dashboard\GetDashboard; |
6
|
|
|
use Marek\Toggable\API\Http\Response\Dashboard\Dashboard as DashboardResponse; |
7
|
|
|
use Marek\Toggable\API\Toggl\Values\Dashboard\Dashboard; |
8
|
|
|
use Marek\Toggable\API\Toggl\Values\Dashboard\Activity; |
9
|
|
|
use Marek\Toggable\API\Toggl\Values\Dashboard\MostActiveUser; |
10
|
|
|
use Marek\Toggable\Service\AbstractService; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class DashboardService |
14
|
|
|
* @package Marek\Toggable\Service\Dashboard |
15
|
|
|
*/ |
16
|
|
|
class DashboardService extends AbstractService implements \Marek\Toggable\API\Toggl\DashboardServiceInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @inheritDoc |
20
|
|
|
*/ |
21
|
2 |
|
public function getDashboardData($workspaceId) |
22
|
|
|
{ |
23
|
2 |
|
$request = new GetDashboard( |
24
|
|
|
array( |
25
|
2 |
|
'workspaceId' => $this->validate($workspaceId), |
26
|
|
|
) |
27
|
1 |
|
); |
28
|
|
|
|
29
|
1 |
|
$response = $this->delegate($request); |
30
|
|
|
|
31
|
1 |
|
$mostActiveUsers = array(); |
32
|
1 |
View Code Duplication |
if (!empty($response->body['most_active_user'])) { |
|
|
|
|
33
|
1 |
|
foreach($response->body['most_active_user'] as $mostActiveUser) { |
34
|
1 |
|
$mostActiveUsers[] = $this->hydrator->hydrate($mostActiveUser, new MostActiveUser()); |
35
|
1 |
|
} |
36
|
1 |
|
} |
37
|
|
|
|
38
|
1 |
|
$activities = array(); |
39
|
1 |
View Code Duplication |
if (!empty($response->body['activity'])) { |
|
|
|
|
40
|
1 |
|
foreach ($response->body['activity'] as $activity) { |
41
|
1 |
|
$activities[] = $this->hydrator->hydrate($activity, new Activity()); |
42
|
1 |
|
} |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
$dashboard = new Dashboard( |
46
|
|
|
array( |
47
|
1 |
|
'activity' => $activities, |
48
|
1 |
|
'mostActiveUser' => $mostActiveUsers, |
49
|
|
|
) |
50
|
1 |
|
); |
51
|
|
|
|
52
|
1 |
|
return new DashboardResponse( |
53
|
|
|
array( |
54
|
1 |
|
'dashboard' => $dashboard, |
55
|
|
|
) |
56
|
1 |
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.