Insurance   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 2
cbo 4
dl 0
loc 114
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getInsurer() 0 4 1
A getDateFrom() 0 4 1
A getDateTo() 0 4 1
A getInsuranceCoverage() 0 4 1
A addInsuranceDocument() 0 4 1
A getInsuranceDocuments() 0 4 1
A changeInsuranceCoverage() 0 4 1
A __construct() 0 14 2
A removeInsuranceDocument() 0 12 3
1
<?php
2
3
namespace Madkom\RegistryApplication\Domain\CarManagement\Insurances;
4
5
use Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException;
6
use Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\NonexistentInsuranceException;
7
8
/**
9
 * Class Insurance.
10
 */
11
class Insurance
12
{
13
    /** @var string $insuranceId */
14
    private $insuranceId;
15
16
    /** @var \DateTime */
17
    private $dateFrom;
18
19
    /** @var \DateTime */
20
    private $dateTo;
21
22
    /** @var string */
23
    private $insurerId;
24
25
    /** @var \Madkom\RegistryApplication\Domain\CarManagement\Insurances\InsuranceDocument[] */
26
    private $documents = [];
27
28
    /** @var string */
29
    private $insuranceCoverage;
30
31
    /**
32
     * Insurance constructor.
33
     *
34
     * @param $dateFrom
35
     * @param $dateTo
36
     * @param $insurerId
37
     *
38
     * @throws \Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException
39
     */
40
    public function __construct($insuranceId, $dateFrom, $dateTo, $insurerId)
41
    {
42
        $dateChecker = new InsuranceDateChecker();
43
        $isInvalidDates = $dateChecker->checkDates($dateFrom, $dateTo);
44
45
        if ($isInvalidDates) {
46
            throw new InvalidDatesException();
47
        }
48
49
        $this->dateFrom = $dateFrom;
50
        $this->dateTo = $dateTo;
51
        $this->insurerId = $insurerId;
52
        $this->insuranceId = $insuranceId;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getId()
59
    {
60
        return $this->insuranceId;
61
    }
62
63
    /**
64
     * @throws \Madkom\RegistryApplication\Domain\CarManagement\Insurances\Exceptions\EmptyInsurerException
65
     *
66
     * @return \Madkom\RegistryApplication\Domain\Insurer\Insurer
67
     */
68
    public function getInsurer()
69
    {
70
        return $this->insurerId;
71
    }
72
73
    /**
74
     * @return \DateTime
75
     */
76
    public function getDateFrom()
77
    {
78
        return $this->dateFrom;
79
    }
80
81
    /**
82
     * @return \DateTime
83
     */
84
    public function getDateTo()
85
    {
86
        return $this->dateTo;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getInsuranceCoverage()
93
    {
94
        return $this->insuranceCoverage;
95
    }
96
97
    public function addInsuranceDocument(InsuranceDocument $newCarDocument)
98
    {
99
        $this->documents[] = $newCarDocument;
100
    }
101
102
    public function getInsuranceDocuments()
103
    {
104
        return $this->documents;
105
    }
106
107
    public function removeInsuranceDocument($documentId)
108
    {
109
        foreach ($this->documents as $key => $document) {
110
            if ($document->getId() === $documentId) {
111
                unset($this->documents[$key]);
112
113
                return 0;
114
            }
115
        }
116
117
        throw new NonexistentInsuranceException();
118
    }
119
120
    public function changeInsuranceCoverage($coverage)
121
    {
122
        $this->insuranceCoverage = $coverage;
123
    }
124
}
125