CuriesHelper::buildCuries()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 8/14/15
6
 * Time: 9:14 PM.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace NilPortugues\Api\Hal\Helpers;
13
14
use NilPortugues\Api\Hal\JsonTransformer;
15
16
final class CuriesHelper
17
{
18
    /**
19
     * @param array $curies
20
     *
21
     * @return array
22
     */
23
    public static function buildCuries(array $curies)
24
    {
25
        $curiesArray = [];
26
        $curies = (array) \array_filter($curies);
27
28
        if (!empty($curies)) {
29
            $curiesArray = [JsonTransformer::LINKS_CURIES => \array_values($curies)];
30
31
            foreach ($curiesArray[JsonTransformer::LINKS_CURIES] as &$value) {
32
                $value[JsonTransformer::LINKS_TEMPLATED_KEY] = true;
33
            }
34
        }
35
36
        return (!empty($curiesArray)) ? $curiesArray : [];
37
    }
38
39
    /**
40
     * @param \NilPortugues\Api\Mapping\Mapping[] $mappings
41
     * @param array                               $curies
42
     * @param string                              $type
43
     */
44
    public static function addCurieForResource(array &$mappings, array &$curies, $type)
45
    {
46
        $curie = $mappings[$type]->getCuries();
47
        if (!empty($curie['name'])) {
48
            $curies[$curie['name']] = $curie;
49
        }
50
    }
51
}
52