Field::extraFields()   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\formgenerator\roa\models;
4
5
use roaresearch\yii2\formgenerator\models as base;
6
use roaresearch\yii2\roa\hal\{Contract, ContractTrait};
7
use yii\{helpers\Url, web\Link, web\NotFoundHttpException};
8
9
/**
10
 * ROA contract handling Field records.
11
 */
12
class Field extends base\Field implements Contract
13
{
14
    use ContractTrait {
15
        getLinks as getContractLinks;
16
    }
17
18
    /**
19
     * @inheritdoc
20
     */
21
    protected $dataTypeClass = DataType::class;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    protected $ruleClass = FieldRule::class;
27
28
    /**
29
     * @inheritdoc
30
     */
31 23
    protected function slugBehaviorConfig(): array
32
    {
33
        return [
34 23
            'resourceName' => 'field',
35 23
            'checkAccess' => function ($params) {
36
                if (
37 12
                    isset($params['field_id'])
38 12
                    && $params['field_id'] != $this->id
39
                ) {
40 1
                    throw new NotFoundHttpException(
41 1
                        'Field doesnt contain the requested route.'
42
                    );
43
                }
44 23
            },
45
        ];
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 5
    public function getLinks()
52
    {
53 5
        $selfLink = $this->getSelfLink();
54
55 5
        return array_merge($this->getContractLinks(), [
56 5
            'rules' => $selfLink . '/rule',
57
            'curies' => [
58 5
                new Link([
59 5
                    'name' => 'embeddable',
60 5
                    '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

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