Completed
Pull Request — master (#6)
by Angel
03:56
created

ContractTrait::getSlugBehaviorId()   A

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 26
    public function behaviors()
16
    {
17 26
        return array_merge(parent::behaviors(), [
18 26
            $this->getSlugBehaviorId() => Instance::ensure(
19 26
                $this->slugBehaviorConfig(),
20 26
                Slug::class
21
            ),
22 26
            $this->getCuriesBehaviorId() => Instance::ensure(
23 26
                $this->curiesBehaviorConfig(),
24 26
                Curies::class
25
            ),
26
        ]);
27
    }
28
29 25
    public function checkAccess(
30
        array $params = [],
31
        ?Action $action = null
32
    ): void {
33 25
        $this->getSlugBehavior()->checkAccess($params, $action);
34 25
    }
35
36
    abstract protected function slugBehaviorConfig(): array|Slug;
37
38 26
    protected function curiesBehaviorConfig(): array
39
    {
40 26
        return [];
41
    }
42
43 26
    protected function getSlugBehaviorId(): string
44
    {
45 26
        return 'slug';
46
    }
47
48 26
    protected function getCuriesBehaviorId(): string
49
    {
50 26
        return 'curies';
51
    }
52
53 25
    public function getSlugBehavior(): Slug
54
    {
55 25
        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 11
    public function getCuriesBehavior(): Curies
59
    {
60 11
        return $this->getBehavior($this->getCuriesBehaviorId());
61
    }
62
63 18
    public function getSelfLink(): string
64
    {
65 18
        return $this->getSlugBehavior()->getSelfLink();
66
    }
67
68 11
    public function getLinks()
69
    {
70 11
        return $this->getSlugBehavior()->getSlugLinks()
71 11
            + $this->getCuriesBehavior()->getCuriesLinks();
72
    }
73
}
74