Completed
Pull Request — master (#2)
by Angel
03:03
created

Curies   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCuriesLinks() 0 23 4
1
<?php
2
3
namespace roaresearch\yii2\roa\behaviors;
4
5
use yii\{helpers\Url, web\Link};
6
7
/**
8
 * Behavior to autogenerate curies links.
9
 *
10
 * @author Angel (Faryshta) Guevara <[email protected]>
11
 */
12
class Curies extends \yii\base\Behavior
13
{
14
    /**
15
     * @var Link[] The curies links. Autogenerated links will be stored here.
16
     */
17
    public $curiesLinks = [];
18
19
    /**
20
     * @var ?string name of the autogenerated expand curie. Set null if you
21
     * don't want to autogenerate expand curie.
22
     */
23
    public $expandCurieName = 'expand';
24
25
    /**
26
     * @var array the configuration used to generate the expand curie.
27
     */
28
    public $expandCurieLink = [
29
        'title' => 'Embeddable related resources.',
30
    ];
31
32
    /**
33
     * Return all the curies and related links.
34
     *
35
     * @return array the configured and autogenerated curies and related links.
36
     */
37
    public function getCuriesLinks(): array
38
    {
39
        if ($this->expandCurieName) {
40
            $this->curiesLinks['curies'][] = new Link(array_merge(
41
                $this->expandCurieLink,
42
                [
43
                    'name' => $this->expandCurieName,
44
                    'href' => $this->owner->getSelfLink()
45
                        . "?{$this->expandCurieName}={rel}",
46
                ]
47
            ));
48
49
            foreach ($this->owner->extraFields() as $field => $value) {
50
                if (is_int($field)) {
51
                    $field = $value;
52
                }
53
54
                $this->curiesLinks["{$this->expandCurieName}:$field"] = $field;
55
            }
56
        }
57
58
        return $this->curiesLinks;
59
    }
60
}
61