Passed
Branch master (9f13d4)
by Alex
50:02 queued 44:57
created

AssociationStubMonomorphic   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
eloc 15
c 4
b 0
f 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isCompatible() 0 14 6
A isOk() 0 9 1
A morphicType() 0 3 1
1
<?php declare(strict_types=1);
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) : bool
13
    {
14
        if (!parent::isCompatible($otherStub)) {
15
            return false;
16
        }
17
18
        if ($this->getThroughFieldChain() !== array_reverse($otherStub->getThroughFieldChain())) {
19
            return false;
20
        }
21
22
        return ($this->getTargType() === $otherStub->getBaseType())
23
            && ($this->getBaseType() === $otherStub->getTargType())
24
            && ($this->getForeignFieldName() === $otherStub->getKeyFieldName())
25
            && ($this->getKeyFieldName() === $otherStub->getForeignFieldName());
26
    }
27
    /**
28
     * Is this AssociationStub sane?
29
     */
30
    public function isOk(): bool
31
    {
32
33
        $isOk = parent::isOk();
34
        $stringCheck = [$this->targType, $this->foreignFieldName];
35
        $checkResult = array_filter($stringCheck, [$this, 'checkStringInput']);
36
        $isOk &= $stringCheck == $checkResult;
37
38
        return boolval($isOk);
39
    }
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function morphicType() : string
44
    {
45
        return 'monomorphic';
46
    }
47
}
48