Solicitude   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 69
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 slugBehaviorConfig() 0 12 3
A getLinks() 0 20 1
A extraFields() 0 3 1
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 Solicitude records.
11
 */
12
class Solicitude extends base\Solicitude implements Contract
13
{
14
    use ContractTrait {
15
        getLinks as getContractLinks;
16
    }
17
18
    /**
19
     * @inheritdoc
20
     */
21
    protected $formClass = Form::class;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    protected $solicitudeValueClass = SolicitudeValue::class;
27
28
    /**
29
     * @inheritdoc
30
     */
31 4
    public function getLinks()
32
    {
33 4
        $selfLink = $this->getSelfLink();
34
35 4
        return array_merge($this->getContractLinks(), [
36 4
            'values' => $selfLink . '/value',
37
            'curies' => [
38 4
                new Link([
39 4
                    'name' => 'embeddable',
40 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

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