ContractTrait::getCuriesBehaviorId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\roa\hal;
4
5
use roaresearch\yii2\roa\behaviors\{Curies, Slug};
6
use yii\{base\Action, di\Instance};
7
8
/**
9
 * Trait which gives the basic support for HAL contracts.
10
 */
11
trait ContractTrait
12
{
13
    use EmbeddableTrait;
14
15 14
    public function behaviors()
16
    {
17 14
        return array_merge(parent::behaviors(), [
18 14
            $this->getSlugBehaviorId() => Instance::ensure(
19 14
                $this->slugBehaviorConfig(),
20
                Slug::class
21
            ),
22 14
            $this->getCuriesBehaviorId() => Instance::ensure(
23 14
                $this->curiesBehaviorConfig(),
24
                Curies::class
25
            ),
26
        ]);
27
    }
28
29 14
    public function checkAccess(
30
        array $params = [],
31
        ?Action $action = null
32
    ): void {
33 14
        $this->getSlugBehavior()->checkAccess($params, $action);
34
    }
35
36
    abstract protected function slugBehaviorConfig(): array|Slug;
37
38 14
    protected function curiesBehaviorConfig(): array
39
    {
40 14
        return [];
41
    }
42
43 14
    protected function getSlugBehaviorId(): string
44
    {
45 14
        return 'slug';
46
    }
47
48 14
    protected function getCuriesBehaviorId(): string
49
    {
50 14
        return 'curies';
51
    }
52
53 14
    public function getSlugBehavior(): Slug
54
    {
55 14
        return $this->getBehavior($this->getSlugBehaviorId());
0 ignored issues
show
Bug introduced by
The method getBehavior() does not exist on roaresearch\yii2\roa\hal\ContractTrait. Did you maybe mean getSlugBehavior()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        return $this->/** @scrutinizer ignore-call */ getBehavior($this->getSlugBehaviorId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
    }
57
58 9
    public function getCuriesBehavior(): Curies
59
    {
60 9
        return $this->getBehavior($this->getCuriesBehaviorId());
61
    }
62
63 12
    public function getSelfLink(): string
64
    {
65 12
        return $this->getSlugBehavior()->getSelfLink();
66
    }
67
68 9
    public function getLinks()
69
    {
70 9
        return $this->getSlugBehavior()->getSlugLinks()
71 9
            + $this->getCuriesBehavior()->getCuriesLinks();
72
    }
73
}
74