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

Form   A

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;
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 Form records.
14
 */
15
class Form extends base\Form implements Contract
16
{
17
    use ContractTrait {
18
        getLinks as getContractLinks;
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24
    protected $sectionClass = Section::class;
25
26
    /**
27
     * @inheritdoc
28
     */
29 5
    public function getLinks()
30
    {
31 5
        $selfLink = $this->getSelfLink();
32
33 5
        return array_merge($this->getContractLinks(), [
34 5
            'sections' => $selfLink . '/section',
35
            'curies' => [
36 5
                new Link([
37 5
                    'name' => 'embeddable',
38 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

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