Test Failed
Pull Request — master (#4)
by
unknown
01:25
created

TogglClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 23.53 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 52.94%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 16
loc 68
ccs 9
cts 17
cp 0.5294
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getWorkspaces() 0 8 1
A getClientsForWorkspace() 8 8 1
A getProjectsForWorkspace() 8 8 1

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 declare(strict_types=1);
2
3
namespace Syncer\Toggl;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use JMS\Serializer\SerializerInterface;
7
use Syncer\Dto\Toggl\Workspace;
8
use Syncer\Dto\Toggl\Client;
9
/**
10
 * Class TogglClient
11
 * @package Syncer\Toggl
12
 *
13
 * @author Matthieu Calie <[email protected]>
14
 */
15
class TogglClient
16
{
17
    const VERSION = 'v8';
18
19
    /**
20
     * @var Client;
21
     */
22
    private $client;
23
24
    /**
25
     * @var SerializerInterface
26
     */
27
    private $serializer;
28
29
    /**
30
     * @var string
31
     */
32
    private $api_key;
33
34
    /**
35
     * TogglClient constructor.
36
     * @param Client $client
37
     * @param SerializerInterface $serializer
38
     * @param $api_key
39
     */
40 2
    public function __construct(GuzzleClient $client, SerializerInterface $serializer, $api_key)
41
    {
42 2
        $this->client = $client;
43 2
        $this->serializer = $serializer;
44 2
        $this->api_key = $api_key;
45 2
    }
46
47
    /**
48
     * @return array|Workspace[]
49
     */
50 1
    public function getWorkspaces()
51
    {
52 1
        $response = $this->client->request('GET', self::VERSION . '/workspaces', [
53 1
            'auth' => [$this->api_key, 'api_token'],
54
        ]);
55
56 1
        return $this->serializer->deserialize($response->getBody(), 'array<Syncer\Dto\Toggl\Workspace>', 'json');
57
    }
58
59
    /**
60
     * @return array|Client[]
61
     */
62 View Code Duplication
    public function getClientsForWorkspace($workspaceId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
63
    {
64
        $response = $this->client->request('GET', self::VERSION . '/workspaces/' . $workspaceId . '/clients', [
65
            'auth' => [$this->api_key, 'api_token'],
66
        ]);
67
68
        return $this->serializer->deserialize($response->getBody(), 'array<Syncer\Dto\Toggl\Client>', 'json');
69
    }
70
71
    /**
72
     * @return array|Project[]
73
     */
74 View Code Duplication
    public function getProjectsForWorkspace($workspaceId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
75
    {
76
        $response = $this->client->request('GET', self::VERSION . '/workspaces/' . $workspaceId . '/projects', [
77
            'auth' => [$this->api_key, 'api_token'],
78
        ]);
79
80
        return $this->serializer->deserialize($response->getBody(), 'array<Syncer\Dto\Toggl\Project>', 'json');
81
    }
82
}
83