TimeCards   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 52
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFromHistoryCards() 0 11 2
A getCardTimeData() 0 4 1
A createTimeCardIfNotExists() 0 11 2
A existsCardTime() 0 10 3
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