Completed
Push — master ( 597b3a...7866ff )
by Sébastien
39s
created

BurndownGenerator   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 98%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 20
c 4
b 1
f 1
lcom 1
cbo 6
dl 0
loc 182
ccs 49
cts 50
cp 0.98
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A addBoard() 0 8 3
C addList() 0 24 8
A addTodoList() 0 4 1
A addWipList() 0 4 1
A addDoneList() 0 4 1
A getBoards() 0 4 1
A getTodoLists() 0 4 1
A getWipLists() 0 4 1
A getDoneLists() 0 4 1
A getStoryPointBurndown() 0 10 1
1
<?php
2
3
namespace TrelloBurndown;
4
5
use Trello\Model\Board;
6
use Trello\Model\Cardlist;
7
use TrelloBurndown\Client\TrelloClient;
8
use TrelloBurndown\Exception\TrelloItemNotFoundException;
9
use TrelloBurndown\Manager\ActionManager;
10
use TrelloBurndown\Manager\BoardManager;
11
use TrelloBurndown\Manager\ListManager;
12
use TrelloBurndown\Manager\StoryPointManager;
13
use TrelloBurndown\Model\Sprint;
14
use TrelloBurndown\Model\StoryPointBurndown;
15
16
/**
17
 * Class BurndownGenerator.
18
 */
19
class BurndownGenerator
20
{
21
    /**
22
     * @var TrelloClient
23
     */
24
    private $client;
25
26
    /**
27
     * @var BoardManager
28
     */
29
    private $boardManager;
30
31
    /**
32
     * @var ListManager
33
     */
34
    private $listManager;
35
36
    /**
37
     * @var ActionManager
38
     */
39
    private $actionManager;
40
41
    /**
42
     * @var StoryPointManager
43
     */
44
    private $storyPointManager;
45
46
    /**
47
     * @var array
48
     */
49
    private $boards = [];
50
51
    /**
52
     * @var array
53
     */
54
    private $todoLists = [];
55
56
    /**
57
     * @var array
58
     */
59
    private $wipLists = [];
60
61
    /**
62
     * @var array
63
     */
64
    private $doneLists = [];
65
66
    /**
67
     * BurndownGenerator constructor.
68
     *
69
     * @param TrelloClient $client
70
     */
71 12
    public function __construct(TrelloClient $client)
72
    {
73 12
        $this->client = $client;
74 12
        $this->boardManager = new BoardManager($this->client);
75 12
        $this->listManager = new ListManager($this->client);
76 12
        $this->actionManager = new ActionManager($this->client);
77 12
        $this->storyPointManager = new StoryPointManager($this->client, $this->actionManager);
78 12
    }
79
80
    /**
81
     * @param string $boardName
82
     *
83
     * @throws \Exception
84
     */
85 10
    public function addBoard(String $boardName)
86
    {
87 10
        $board = $this->boardManager->getBoard($boardName);
88 10
        if ($board ==  null || !$board instanceof Board) {
89 1
            throw new TrelloItemNotFoundException('board', $boardName);
90
        }
91 9
        $this->boards[] = $board;
92 9
    }
93
94
    /**
95
     * @param array  $lists
96
     * @param string $listName
97
     * @param $boardName
98
     *
99
     * @throws \Exception
100
     */
101 9
    private function addList(array &$lists, String $listName, $boardName)
102
    {
103 9
        if ($boardName !== null) {
104 5
            $board = $this->boardManager->getBoard($boardName);
105
106 5
            if ($board ==  null || !$board instanceof Board) {
107 1
                throw new TrelloItemNotFoundException('board', $boardName);
108
            }
109
110 4
            $list = $this->listManager->getListFromBoard($listName, $board);
111
112 4
            if ($list == null || !$list instanceof Cardlist) {
113
                throw new TrelloItemNotFoundException('list', $listName);
114
            }
115
116 4
            $lists[] = $list;
117
        } else {
118 4
            $list = $this->listManager->getList($listName, $this->boards);
119 4
            if ($list == null || !$list instanceof Cardlist) {
120 1
                throw new TrelloItemNotFoundException('list', $listName);
121
            }
122 3
            $lists[] = $list;
123
        }
124 7
    }
125
126
    /**
127
     * @param string      $listName
128
     * @param string|null $boardName
129
     */
130 3
    public function addTodoList(String $listName, String $boardName = null)
131
    {
132 3
        $this->addList($this->todoLists, $listName, $boardName);
133 3
    }
134
135
    /**
136
     * @param string      $listName
137
     * @param string|null $boardName
138
     */
139 5
    public function addWipList(String $listName, String $boardName = null)
140
    {
141 5
        $this->addList($this->wipLists, $listName, $boardName);
142 3
    }
143
144
    /**
145
     * @param string      $listName
146
     * @param string|null $boardName
147
     */
148 3
    public function addDoneList(String $listName, String $boardName = null)
149
    {
150 3
        $this->addList($this->doneLists, $listName, $boardName);
151 3
    }
152
153
    /**
154
     * @return array
155
     */
156 5
    public function getBoards()
157
    {
158 5
        return $this->boards;
159
    }
160
161
    /**
162
     * @return array
163
     */
164 2
    public function getTodoLists()
165
    {
166 2
        return $this->todoLists;
167
    }
168
169
    /**
170
     * @return array
171
     */
172 2
    public function getWipLists()
173
    {
174 2
        return $this->wipLists;
175
    }
176
177
    /**
178
     * @return array
179
     */
180 2
    public function getDoneLists()
181
    {
182 2
        return $this->doneLists;
183
    }
184
185
    /**
186
     * @param Sprint $sprint
187
     *
188
     * @return StoryPointBurndown
189
     */
190 1
    public function getStoryPointBurndown(Sprint $sprint)
191
    {
192 1
        $doneSP = $this->storyPointManager->getDoneStoryPoints($this->todoLists, $this->wipLists, $this->doneLists, $sprint);
193 1
        $total = $this->storyPointManager->getTotalSprintStoryPoints($this->todoLists, $this->wipLists, $this->doneLists, $sprint);
194 1
        $average = $this->storyPointManager->getAverageStoryPointsPerDay($total, $sprint);
195
196 1
        $burndown = new StoryPointBurndown($sprint, $total, $doneSP, $average);
0 ignored issues
show
Bug introduced by
It seems like $doneSP defined by $this->storyPointManager...is->doneLists, $sprint) on line 192 can also be of type null; however, TrelloBurndown\Model\Sto...Burndown::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
197
198 1
        return $burndown;
199
    }
200
}
201