Section::getLinks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 20
ccs 14
cts 14
cp 1
crap 1
rs 9.7998
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};
8
9
/**
10
 * ROA contract handling Section records.
11
 */
12
class Section extends base\Section 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 $sectionFieldClass = SectionField::class;
27
28
    /**
29
     * @inheritdoc
30
     */
31
    protected $fieldClass = Field::class;
32
33
    /**
34
     * @inheritdoc
35
     */
36 4
    public function getLinks()
37
    {
38 4
        $selfLink = $this->getSelfLink();
39
40 4
        return array_merge($this->getContractLinks(), [
41 4
            'fields' => $selfLink . '/field',
42
            'curies' => [
43 4
                new Link([
44 4
                    'name' => 'embeddable',
45 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

45
                    'href' => Url::to($selfLink, /** @scrutinizer ignore-type */ ['expand' => '{rel}']),
Loading history...
46 4
                    'title' => 'Embeddable and not Nestable related resources.',
47
                ]),
48 4
                new Link([
49 4
                    'name' => 'nestable',
50 4
                    'href' => Url::to($selfLink, ['expand' => '{rel}']),
51 4
                    'title' => 'Embeddable and Nestable related resources.',
52
                ]),
53
            ],
54 4
            'embeddable:fields' => 'fields',
55 4
            'nestable:form' => 'form',
56
        ]);
57
    }
58
    
59
    /**
60
     * @inheritdoc
61
     */
62 15
    protected function slugBehaviorConfig(): array
63
    {
64
        return [
65 15
            'resourceName' => 'section',
66
            'parentSlugRelation' => 'form',
67
        ];
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73 4
    public function extraFields()
74
    {
75 4
        return ['form', 'fields', 'sectionFields'];
76
    }
77
}
78