Test Failed
Pull Request — master (#1)
by Carlos
03:47
created

FieldRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 70
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLinks() 0 20 1
A extraFields() 0 3 1
A slugBehaviorConfig() 0 12 3
1
<?php
2
3
namespace roaresearch\yii2\formgenerator\roa\models;
4
5
use roaresearch\yii2\formgenerator\models as base;
6
use roaresearch\yii2\roa\hal\Contract;
7
use roaresearch\yii2\roa\hal\ContractTrait;
8
use yii\helpers\Url;
9
use yii\web\Link;
10
11
/**
12
 * ROA contract handling FieldRule records.
13
 */
14
class FieldRule extends base\FieldRule implements Contract
15
{
16
    use ContractTrait {
17
        getLinks as getContractLinks;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    protected $fieldClass = Field::class;
24
25
    /**
26
     * @inheritdoc
27
     */
28
29
    protected $propertyClass = FieldRuleProperty::class;
30
31
    /**
32
     * @inheritdoc
33
     */
34 9
    protected function slugBehaviorConfig(): array
35
    {
36
        return [
37 9
            'resourceName' => 'rule',
38 9
            'parentSlugRelation' => 'field',
39 9
            'checkAccess' => function ($params) {
40 8
                if (
41 8
                    isset($params['rule_id'])
42
                    && $params['rule_id'] != $this->id
43
                ) {
44
                    throw new NotFoundHttpException(
0 ignored issues
show
Bug introduced by
The type roaresearch\yii2\formgen...s\NotFoundHttpException 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...
45
                        'Field Rule doesnt contain the requested route.'
46
                    );
47 9
                }
48
            }
49
        ];
50
    }
51
52
    /**
53
     * @inheritdoc
54 4
     */
55
    public function getLinks()
56 4
    {
57
        $selfLink = $this->getSelfLink();
58 4
59 4
        return array_merge($this->getContractLinks(), [
60
            'properties' => $selfLink . '/property',
61 4
            'curies' => [
62 4
                new Link([
63 4
                    'name' => 'embeddable',
64 4
                    'href' => Url::to($selfLink, ['expand' => '{rel}']),
0 ignored issues
show
Bug introduced by
array('expand' => '{rel}') of type array<string,string> is incompatible with the type boolean|string expected by parameter $scheme of yii\helpers\BaseUrl::to(). ( Ignorable by Annotation )

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

64
                    'href' => Url::to($selfLink, /** @scrutinizer ignore-type */ ['expand' => '{rel}']),
Loading history...
65
                    'title' => 'Embeddable and not Nestable related resources.',
66 4
                ]),
67 4
                new Link([
68 4
                    'name' => 'nestable',
69 4
                    'href' => Url::to($selfLink, ['expand' => '{rel}']),
70
                    'title' => 'Embeddable and Nestable related resources.',
71
                ]),
72 4
            ],
73 4
            'embeddable:properties' => 'properties',
74
            'nestable:field' => 'field',
75
        ]);
76
    }
77
78
    /**
79
     * @inheritdoc
80 4
     */
81
    public function extraFields()
82 4
    {
83
        return ['field', 'properties'];
84
    }
85
}
86