Completed
Push — master ( 5ccfa5...c047c7 )
by Mario
03:23
created

DashboardService::getDashboardData()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 37
Code Lines 20

Duplication

Lines 10
Ratio 27.03 %

Code Coverage

Tests 20
CRAP Score 8.1426

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 10
loc 37
ccs 20
cts 28
cp 0.7143
rs 6.7272
cc 7
eloc 20
nc 5
nop 1
crap 8.1426
1
<?php
2
3
namespace Marek\Toggable\Service\Dashboard;
4
5
use InvalidArgumentException;
6
use Marek\Toggable\API\Http\Request\Dashboard\GetDashboard;
7
use Marek\Toggable\API\Http\Response\Dashboard\Dashboard as DashboardResponse;
8
use Marek\Toggable\API\Toggl\Values\Dashboard\Dashboard;
9
use Marek\Toggable\API\Http\Response\Error;
10
use Marek\Toggable\API\Toggl\Values\Dashboard\Activity;
11
use Marek\Toggable\API\Toggl\Values\Dashboard\MostActiveUser;
12
use Marek\Toggable\Service\AbstractService;
13
14
/**
15
 * Class DashboardService
16
 * @package Marek\Toggable\Service\Dashboard
17
 */
18
class DashboardService extends AbstractService implements \Marek\Toggable\API\Toggl\DashboardServiceInterface
19
{
20
    /**
21
     * @inheritDoc
22
     */
23 2
    public function getDashboardData($workspaceId)
24
    {
25 2
        if (empty($workspaceId) || !is_int($workspaceId)) {
26 1
            throw new InvalidArgumentException(
27 1
                sprintf('$workspaceId argument not provided in %s', get_class($this))
28 1
            );
29
        }
30
31 1
        $request = new GetDashboard(array(
32 1
            'workspaceId' => $workspaceId,
33 1
        ));
34
35 1
        $response = $this->delegate($request);
36
37 1
        $mostActiveUsers = array();
38 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...
39
            foreach($response->body['most_active_user'] as $mostActiveUser) {
40
                $mostActiveUsers[] = $this->hydrator->hydrate($mostActiveUser, new MostActiveUser());
41
            }
42
        }
43
44 1
        $activities = array();
45 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...
46
            foreach ($response->body['activity'] as $activity) {
47
                $activities[] = $this->hydrator->hydrate($activity, new Activity());
48
            }
49
        }
50
51 1
        $dashboard = new Dashboard(array(
52 1
            'activity' => $activities,
53 1
            'mostActiveUser' => $mostActiveUsers,
54 1
        ));
55
56 1
        return new DashboardResponse(array(
57 1
            'dashboard' => $dashboard,
58 1
        ));
59
    }
60
}
61