Completed
Pull Request — MetadataImplementationStep (#116)
by Alex
01:56
created

AssociationMonomorphic::getArrayPayload()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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