Completed
Pull Request — master (#1)
by Angel
07:01
created

Solicitude::extraFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
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;
7
use roaresearch\yii2\roa\hal\ContractTrait;
8
use yii\helpers\Url;
9
use yii\web\Link;
10
use yii\web\NotFoundHttpException;
11
12
/**
13
 * ROA contract handling Solicitude records.
14
 */
15
class Solicitude extends base\Solicitude implements Contract
16
{
17
    use ContractTrait {
18
        getLinks as getContractLinks;
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24
    protected $formClass = Form::class;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    protected $solicitudeValueClass = SolicitudeValue::class;
30
31
    /**
32
     * @inheritdoc
33
     */
34 4
    public function getLinks()
35
    {
36 4
        $selfLink = $this->getSelfLink();
37
38 4
        return array_merge($this->getContractLinks(), [
39 4
            'values' => $selfLink . '/value',
40
            'curies' => [
41 4
                new Link([
42 4
                    'name' => 'embeddable',
43 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

43
                    'href' => Url::to($selfLink, /** @scrutinizer ignore-type */ ['expand' => '{rel}']),
Loading history...
44 4
                    'title' => 'Embeddable and not Nestable related resources.',
45
                ]),
46 4
                new Link([
47 4
                    'name' => 'nestable',
48 4
                    'href' => Url::to($selfLink, ['expand' => '{rel}']),
49 4
                    'title' => 'Embeddable and Nestable related resources.',
50
                ]),
51
            ],
52 4
            'embeddable:values' => 'values',
53 4
            'nestable:form' => 'form',
54
        ]);
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 11
    protected function slugBehaviorConfig(): array
61
    {
62
        return [
63 11
            'resourceName' => 'solicitude',
64 11
            'parentSlugRelation' => 'form',
65 11
            'checkAccess' => function ($params) {
66 8
                if (
67 8
                    isset($params['solicitude_id'])
68
                    && $params['solicitude_id'] != $this->id
69
                ) {
70
                    throw new NotFoundHttpException(
71
                        'Solicitude doesnt contain the requested route.'
72
                    );
73 11
                }
74
            },
75
        ];
76
    }
77
78
    /**
79
     * @inheritdoc
80 4
     */
81
    public function extraFields()
82 4
    {
83
        return ['form', 'values'];
84
    }
85
}
86