TimeCards::getCardTimeData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TrelloCycleTime\Collection;
6
7
8
use TrelloCycleTime\ValueObject\HistoryCard;
9
use TrelloCycleTime\ValueObject\TimeCard;
10
11
class TimeCards
12
{
13
    private $timeCards;
14
    private $cycleTimeCollection;
15
    private $historyCards;
16
    private $cardHistoryCollection;
17
18 5
    public function __construct()
19
    {
20 5
        $this->timeCards = [];
21 5
    }
22
23 5
    public function getFromHistoryCards(HistoryCards $historyCards) :array
24
    {
25 5
        $this->historyCards = $historyCards;
26 5
        $this->cardHistoryCollection = $historyCards->getCardHistories();
27
28 5
        foreach ($this->cardHistoryCollection as $cardHistory) {
29 3
            $this->createTimeCardIfNotExists($cardHistory);
30
        }
31
32 5
        return $this->getCardTimeData();
33
    }
34
35 5
    public function getCardTimeData(): array
36
    {
37 5
        return $this->timeCards;
38
    }
39
40 3
    private function createTimeCardIfNotExists(HistoryCard $cardHistory) {
41 3
        if (!$this->existsCardTime($cardHistory->getId())) {
42 3
            $cycleTimeCollection = new CycleTimesCollection();
43 3
            $this->cycleTimeCollection = $cycleTimeCollection->getFromCardHistory($this->cardHistoryCollection);
44
45 3
            $this->timeCards[] = TimeCard::create(
46 3
                $cardHistory->getId(),
47 3
                $cardHistory->getTitle()
48
            );
49
        }
50 3
    }
51
52 3
    private function existsCardTime(string $id): bool
53
    {
54 3
        foreach ($this->timeCards as $cardTime) {
55 2
            if ($cardTime->getId() === $id) {
56 2
                return true;
57
            }
58
        }
59
60 3
        return false;
61
    }
62
}
63