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

DashboardService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 71.43%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 7
c 6
b 0
f 0
lcom 1
cbo 8
dl 10
loc 43
ccs 20
cts 28
cp 0.7143
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C getDashboardData() 10 37 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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