ListManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 15.63 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 4
dl 10
loc 64
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getListFromBoard() 5 12 3
B getList() 5 19 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 TrelloBurndown\Manager;
4
5
use Trello\Model\Board;
6
use TrelloBurndown\Client\TrelloClient;
7
use Trello\Model\Cardlist;
8
9
/**
10
 * Class ListManager.
11
 */
12
class ListManager
13
{
14
    /**
15
     * @var \Trello\Client
16
     */
17
    private $client;
18
19
    /**
20
     * ListManager constructor.
21
     *
22
     * @param TrelloClient $client
23
     */
24 18
    public function __construct(TrelloClient $client)
25
    {
26 18
        $this->client = $client->getClient();
27 18
    }
28
29
    /**
30
     * @param string $listName
31
     * @param Board  $board
32
     *
33
     * @return Cardlist|void
34
     */
35 6
    public function getListFromBoard(String $listName, Board $board)
36
    {
37 6
        $lists = $this->client->api('board')->lists()->all($board->getId());
38
39 6 View Code Duplication
        foreach ($lists as $list) {
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 6
            if ($list['name'] == $listName) {
41 6
                return new Cardlist($this->client, $list['id']);
42
            }
43
        }
44
45 1
        return;
46
    }
47
48
    /**
49
     * @param string $listName
50
     * @param array  $boards
51
     *
52
     * @return Cardlist|void
53
     *
54
     * @throws \Exception
55
     */
56 7
    public function getList(String $listName, array $boards)
57
    {
58 7
        $lists = [];
59 7
        foreach ($boards as $board) {
60 7
            if (!($board instanceof Board)) {
61 1
                throw new \Exception('Function ListManager::getList expect an array of Board as second argument');
62
            }
63
64 7
            $lists = array_merge($lists, $this->client->api('board')->lists()->all($board->getId()));
65
        }
66
67 6 View Code Duplication
        foreach ($lists as $list) {
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...
68 6
            if ($list['name'] == $listName) {
69 6
                return new Cardlist($this->client, $list['id']);
70
            }
71
        }
72
73 2
        return;
74
    }
75
}
76