Completed
Push — 1.1 ( 17428c...7dea68 )
by David
10:20
created

ImmutableAssetType::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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