AssociationMonomorphic::isOk()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 4
nc 4
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations;
6
7
class AssociationMonomorphic extends Association
8
{
9
10
    /**
11
     * @var AssociationStubBase
12
     */
13
    protected $last;
14
15
    /**
16
     * @return AssociationStubBase
17
     */
18
    public function getLast(): AssociationStubBase
19
    {
20
        return $this->last;
21
    }
22
23
    /**
24
     * @param AssociationStubBase $last
25
     */
26
    public function setLast(AssociationStubBase $last): void
27
    {
28
        $this->last = $last;
29
        $last->addAssociation($this);
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    public function isOk(): bool
36
    {
37
        $first = $this->getFirst();
38
        $last  = $this->getLast();
39
        if (!$first->isOk()) {
40
            return false;
41
        }
42
        if (!$last->isOk()) {
43
            return false;
44
        }
45
        if (!$first->isCompatible($last)) {
46
            return false;
47
        }
48
        return -1 === $first->compare($last);
49
    }
50
51
    /**
52
     * @return \AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations\AssociationType
53
     */
54
    public function getAssociationType(): AssociationType
55
    {
56
        return new AssociationType($this->first->getMultiplicity()->getValue()
57
                                    | $this->last->getMultiplicity()->getValue());
58
    }
59
}
60