ImmutableAssetType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getAssets() 0 4 1
A fromArray() 0 7 1
1
<?php
2
namespace TheCodingMachine\Discovery;
3
4
/**
5
 * An asset type is essentially an array of Assets
6
 */
7
class ImmutableAssetType implements AssetTypeInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $name;
13
14
    /**
15
     * @var Asset[]
16
     */
17
    private $assets = [];
18
19
    public function __construct(string $name, array $assets)
20
    {
21
        $this->name = $name;
22
        $this->assets = $assets;
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getName(): string
29
    {
30
        return $this->name;
31
    }
32
33
    /**
34
     * @return Asset[]
35
     */
36
    public function getAssets() : array
37
    {
38
        return $this->assets;
39
    }
40
41
    /**
42
     * Creates an ImmutableAssetType from a PHP array.
43
     *
44
     * @param string $name
45
     * @param array $assetsArray
46
     * @return ImmutableAssetType
47
     */
48
    public static function fromArray(string $name, array $assetsArray) : ImmutableAssetType
49
    {
50
        $assets = array_map(function (array $assetArray) {
51
            return Asset::fromArray($assetArray);
52
        }, $assetsArray);
53
        return new self($name, $assets);
54
    }
55
}
56