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

AssociationStubMonomorphic::isOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
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