Completed
Push — master ( 9f13d4...a886ae )
by Alex
38:38 queued 38:36
created

AssociationStubMonomorphic::isOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations;
6
7
class AssociationStubMonomorphic extends AssociationStubBase
8
{
9
    /**
10
     * @param \AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations\AssociationStubBase $otherStub
11
     *
12
     * @return bool
13
     */
14
    public function isCompatible(AssociationStubBase $otherStub): bool
15
    {
16
        if (!parent::isCompatible($otherStub)) {
17
            return false;
18
        }
19
20
        if ($this->getThroughFieldChain() !== array_reverse($otherStub->getThroughFieldChain())) {
21
            return false;
22
        }
23
24
        return ($this->getTargType() === $otherStub->getBaseType())
25
            && ($this->getBaseType() === $otherStub->getTargType())
26
            && ($this->getForeignFieldName() === $otherStub->getKeyFieldName())
27
            && ($this->getKeyFieldName() === $otherStub->getForeignFieldName());
28
    }
29
    /**
30
     * Is this AssociationStub sane?
31
     */
32
    public function isOk(): bool
33
    {
34
        $isOk        = parent::isOk();
35
        $stringCheck = [$this->targType, $this->foreignFieldName];
36
        $checkResult = array_filter($stringCheck, [$this, 'checkStringInput']);
37
        $isOk &= $stringCheck == $checkResult;
38
39
        return boolval($isOk);
40
    }
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function morphicType(): string
45
    {
46
        return 'monomorphic';
47
    }
48
}
49