Completed
Pull Request — master (#6)
by aguevaraIL
18:47
created

ContractTrait::checkAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 2
dl 0
loc 5
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};
0 ignored issues
show
Bug introduced by
The type roaresearch\yii2\roa\behaviors\Slug was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use yii\base\Action;
7
8
/**
9
 * Trait which gives the basic support for HAL contracts.
10
 */
11
trait ContractTrait
12
{
13
    use EmbeddableTrait;
14 14
15
    public function behaviors()
16 14
    {
17 14
        return array_merge(parent::behaviors(), [
18 14
            $this->getSlugBehaviorId() => ['class' => Slug::class]
19 14
                + $this->slugBehaviorConfig(),
20 14
            $this->getCuriesBehaviorId() => ['class' => Curies::class]
21
                + $this->curiesBehaviorConfig(),
22
        ]);
23
    }
24
25
    public function checkAccess(
26 14
        array $params = [],
27
        ?Action $action = null
28 14
    ): void {
29
        $this->getSlugBehavior()->checkAccess($params, $action);
30
    }
31 14
32
    abstract protected function slugBehaviorConfig(): array;
33 14
34
    protected function curiesBehaviorConfig(): array
35
    {
36 14
        return [];
37
    }
38 14
39
    protected function getSlugBehaviorId(): string
40
    {
41 12
        return 'slug';
42
    }
43 12
44
    protected function getCuriesBehaviorId(): string
45
    {
46 9
        return 'curies';
47
    }
48 9
49
    public function getSlugBehavior(): Slug
50
    {
51 12
        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

51
        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...
52
    }
53 12
54
    public function getCuriesBehavior(): Curies
55
    {
56 9
        return $this->getBehavior($this->getCuriesBehaviorId());
57
    }
58 9
59 9
    public function getSelfLink(): string
60
    {
61
        return $this->getSlugBehavior()->getSelfLink();
62
    }
63
64
    public function getLinks()
65
    {
66
        return $this->getSlugBehavior()->getSlugLinks()
67
            + $this->getCuriesBehavior()->getCuriesLinks();
68
    }
69
}
70