DashboardService::getDashboardData()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 37
Code Lines 20

Duplication

Lines 10
Ratio 27.03 %

Code Coverage

Tests 24
CRAP Score 5

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 10
loc 37
ccs 24
cts 24
cp 1
rs 8.439
cc 5
eloc 20
nc 4
nop 1
crap 5
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'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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