Completed
Push — master ( c20ba1...70ca3b )
by Mario
03:39
created

DashboardService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 5
c 7
b 0
f 0
lcom 1
cbo 8
dl 10
loc 43
ccs 24
cts 24
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getDashboardData() 10 37 5

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 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