Passed
Push — master ( 5ee49d...ede548 )
by Alessandro
01:05 queued 11s
created

TrelloBoard::getCardTransitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TrelloCycleTime;
6
7
use TrelloCycleTime\Client\TrelloApiClient;
8
use TrelloCycleTime\Collection\CardsIdCollection;
9
use TrelloCycleTime\Collection\HistoryCards;
10
use TrelloCycleTime\Collection\TimeCards;
11
12
final class TrelloBoard
13
{
14
15
    private $client;
16
17
    private $historyCardsCollection;
18
19
    private $timeCards;
20
    /**
21
     * @var string
22
     */
23
    private $boardId;
24
    /**
25
     * @var Filter
26
     */
27
    private $filter;
28
29 3
    public function __construct(TrelloApiClient $client, string $boardId)
30
    {
31 3
        $this->client = $client;
32 3
        $this->timeCards = new TimeCards();
33 3
        $this->boardId = $boardId;
34 3
    }
35
36 2
    public function getTransitions(array $filters = []) :array
37
    {
38 2
        $this->filter = Filter::createFromArray($filters);
39 2
        $cards = CardsIdCollection::createFromArray($this->client->findAllCards($this->boardId));
40
41 2
        $this->historyCardsCollection = HistoryCards::createFromCards($this->client, $cards->getCardsId());
42
43 2
        return $this->calculateTimeCardsCycleTime();
44
    }
45
46 1
    public function getCardTransitions(string $cardId, array $filters = []) :array
47
    {
48 1
        $this->filter = Filter::createFromArray($filters);
49 1
        $cards = CardsIdCollection::createFromId($cardId);
50
51 1
        $this->historyCardsCollection = HistoryCards::createFromCards($this->client, $cards->getCardsId());
52
53 1
        return $this->calculateTimeCardsCycleTime();
54
    }
55
56 3
    private function calculateTimeCardsCycleTime()
57
    {
58 3
        $timeCards = $this->timeCards->getFromHistoryCards($this->historyCardsCollection, $this->filter);
0 ignored issues
show
Unused Code introduced by
The call to TimeCards::getFromHistoryCards() has too many arguments starting with $this->filter.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
60 3
        $cycleTimeCalculator = new CycleTimeCalculator($timeCards, $this->historyCardsCollection);
61
62 3
        if ($this->filter->isFromColumnEnabled() && $this->filter->isToColumnEnabled()) {
63
            $cycleTimeCalculator->calculateWithStaticFromAndTo($this->filter->getFromColumn(), $this->filter->getToColumn());
64
        } else {
65 3
            $cycleTimeCalculator->calculateFromCardHistory();
66
        }
67
68 3
        return $cycleTimeCalculator->getTimeCards();
69
    }
70
}