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

Section::extraFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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
11
/**
12
 * ROA contract handling Section records.
13
 */
14
class Section extends base\Section implements Contract
15
{
16
    use ContractTrait {
17
        getLinks as getContractLinks;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    protected $formClass = Form::class;
24
25
    /**
26
     * @inheritdoc
27
     */
28
    protected $sectionFieldClass = SectionField::class;
29
30
    /**
31
     * @inheritdoc
32
     */
33
    protected $fieldClass = Field::class;
34
35
    /**
36
     * @inheritdoc
37
     */
38 4
    public function getLinks()
39
    {
40 4
        $selfLink = $this->getSelfLink();
41
42 4
        return array_merge($this->getContractLinks(), [
43 4
            'fields' => $selfLink . '/field',
44
            'curies' => [
45 4
                new Link([
46 4
                    'name' => 'embeddable',
47 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

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