LinkFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 45
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 7 2
A createLink() 0 4 1
A createCollection() 0 8 2
1
<?php
2
namespace Aeq\Hal\Explorer;
3
4
use Aeq\Hal\Explorer;
5
use Aeq\Hal\Utils\ArrayUtils;
6
7
class LinkFactory
8
{
9
    /**
10
     * @param Explorer $explorer
11
     * @param string $name
12
     * @param array $data
13
     * @param EmbeddableInterface $parent
14
     * @return LinkInterface
15
     */
16 5
    public static function create(Explorer $explorer, $name, array $data, EmbeddableInterface $parent)
17
    {
18 5
        if (ArrayUtils::isNumericArray($data)) {
19 1
            return self::createCollection($explorer, $name, $data, $parent);
20
        }
21 5
        return self::createLink($explorer, $name, $data, $parent);
22
    }
23
24
    /**
25
     * @param Explorer $explorer
26
     * @param string $name
27
     * @param array $data
28
     * @param EmbeddableInterface $parent
29
     * @return Link
30
     */
31 5
    public static function createLink(Explorer $explorer, $name, array $data, EmbeddableInterface $parent)
32
    {
33 5
        return new Link($explorer, $name, $data, $parent);
34
    }
35
36
    /**
37
     * @param Explorer $explorer
38
     * @param string $name
39
     * @param array $data
40
     * @param EmbeddableInterface $parent
41
     * @return LinkCollection
42
     */
43 1
    public static function createCollection(Explorer $explorer, $name, array $data, EmbeddableInterface $parent)
44
    {
45 1
        $collection =  new LinkCollection($explorer, $name, $parent);
46 1
        foreach ($data as $itemData) {
47 1
            $collection->addLink(self::createLink($explorer, $name, $itemData, $collection));
48 1
        }
49 1
        return $collection;
50
    }
51
}
52