CuriesHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCuries() 0 15 4
A addCurieForResource() 0 7 2
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