ListManager::getList()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 19
Code Lines 10

Duplication

Lines 5
Ratio 26.32 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 5
loc 19
ccs 10
cts 10
cp 1
rs 8.8571
cc 5
eloc 10
nc 7
nop 2
crap 5
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