Passed
Pull Request — master (#221)
by Christopher
13:40
created

AssociationStubMonomorphic   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
eloc 21
c 2
b 0
f 0
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B isCompatible() 0 28 9
A morphicType() 0 3 1
1
<?php
2
3
namespace AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations;
4
5
class AssociationStubMonomorphic extends AssociationStubBase
6
{
7
    /**
8
     * @param \AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations\AssociationStubBase $otherStub
9
     *
10
     * @return bool
11
     */
12
    public function isCompatible(AssociationStubBase $otherStub)
13
    {
14
        if (!parent::isCompatible($otherStub)) {
15
            return false;
16
        }
17
        $isNull = null == $this->getThroughField();
18
        $otherNull = null == $otherStub->getThroughField();
19
20
        if ($isNull != $otherNull) {
21
            return false;
22
        }
23
        $thisChain = $this->getThroughFieldChain();
24
        $otherChain = $otherStub->getThroughFieldChain();
25
        $thisThroughCount = count($thisChain) - 1;
26
        $otherThroughCount = count($otherChain) - 1;
27
        if ($thisThroughCount !== $otherThroughCount) {
28
            return false;
29
        }
30
        for($i=0; $i <= $thisThroughCount;++$i ){
31
            if($thisChain[$i] !== $otherChain[$otherThroughCount -$i]){
32
                return false;
33
            }
34
        }
35
36
        return ($this->getTargType() === $otherStub->getBaseType())
37
            && ($this->getBaseType() === $otherStub->getTargType())
38
            && ($this->getForeignField() === $otherStub->getKeyField())
39
            && ($this->getKeyField() === $otherStub->getForeignField());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function morphicType()
46
    {
47
        return 'monomorphic';
48
    }
49
}
50