Form   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 57
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A extraFields() 0 3 1
A getLinks() 0 14 1
A slugBehaviorConfig() 0 11 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, ContractTrait};
7
use yii\{helpers\Url, web\Link, web\NotFoundHttpException};
8
9
/**
10
 * ROA contract handling Form records.
11
 */
12
class Form extends base\Form implements Contract
13
{
14
    use ContractTrait {
15
        getLinks as getContractLinks;
16
    }
17
18
    /**
19
     * @inheritdoc
20
     */
21
    protected $sectionClass = Section::class;
22
23
    /**
24
     * @inheritdoc
25
     */
26 5
    public function getLinks()
27
    {
28 5
        $selfLink = $this->getSelfLink();
29
30 5
        return array_merge($this->getContractLinks(), [
31 5
            'sections' => $selfLink . '/section',
32
            'curies' => [
33 5
                new Link([
34 5
                    'name' => 'embeddable',
35 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

35
                    'href' => Url::to($selfLink, /** @scrutinizer ignore-type */ ['expand' => '{rel}']),
Loading history...
36 5
                    'title' => 'Embeddable and not Nestable related resources.',
37
                ]),
38
            ],
39 5
            'embeddable:sections' => 'sections',
40
        ]);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 26
    protected function slugBehaviorConfig(): array
47
    {
48
        return [
49 26
            'resourceName' => 'form',
50 26
            'checkAccess' => function ($params) {
51
                if (
52 24
                    isset($params['form_id'])
53 24
                    && $params['form_id'] != $this->id
54
                ) {
55 5
                    throw new NotFoundHttpException(
56 5
                        'Field doesnt contain the requested route.'
57
                    );
58
                }
59 26
            },
60
        ];
61
    }
62
    
63
    /**
64
     * @inheritdoc
65
     */
66 5
    public function extraFields()
67
    {
68 5
        return ['sections'];
69
    }
70
}
71