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

Asset   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 102
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getValue() 0 4 1
A getPackage() 0 4 1
A getPackageDir() 0 4 1
A getPriority() 0 4 1
A getMetadata() 0 4 1
A jsonSerialize() 0 10 1
A fromArray() 0 4 1
1
<?php
2
3
4
namespace TheCodingMachine\Discovery;
5
6
/**
7
 * Represent an asset.
8
 * Returned by the "getAssets" method.
9
 */
10
class Asset implements \JsonSerializable
11
{
12
    /**
13
     * @var string
14
     */
15
    private $value;
16
    /**
17
     * @var string
18
     */
19
    private $package;
20
    /**
21
     * @var string
22
     */
23
    private $packageDir;
24
    /**
25
     * @var float
26
     */
27
    private $priority;
28
29
    /**
30
     * @var mixed
31
     */
32
    private $metadata;
33
34
    public function __construct(string $value, string $package, string $packageDir, float $priority, $metadata)
35
    {
36
        $this->value = $value;
37
        $this->package = $package;
38
        $this->packageDir = $packageDir;
39
        $this->priority = $priority;
40
        $this->metadata = $metadata;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getValue(): string
47
    {
48
        return $this->value;
49
    }
50
51
    /**
52
     * Returns the name of the Composer package.
53
     *
54
     * @return string
55
     */
56
    public function getPackage(): string
57
    {
58
        return $this->package;
59
    }
60
61
    /**
62
     * Returns the package directory, relative to root directory.
63
     *
64
     * @return string
65
     */
66
    public function getPackageDir(): string
67
    {
68
        return $this->packageDir;
69
    }
70
71
    /**
72
     * The higher the priority the earlier the asset in the array.
73
     *
74
     * @return float
75
     */
76
    public function getPriority(): float
77
    {
78
        return $this->priority;
79
    }
80
81
    /**
82
     * @return mixed
83
     */
84
    public function getMetadata()
85
    {
86
        return $this->metadata;
87
    }
88
89
    /**
90
     * Specify data which should be serialized to JSON
91
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
92
     * @return mixed data which can be serialized by <b>json_encode</b>,
93
     * which is a value of any type other than a resource.
94
     * @since 5.4.0
95
     */
96
    public function jsonSerialize()
97
    {
98
        return [
99
            'value' => $this->getValue(),
100
            'package' => $this->getPackage(),
101
            'packageDir' => $this->getPackageDir(),
102
            'priority' => $this->getPriority(),
103
            'metadata' => $this->getMetadata()
104
        ];
105
    }
106
107
    public static function fromArray(array $array) : Asset
108
    {
109
        return new self($array['value'], $array['package'], $array['packageDir'], $array['priority'], $array['metadata']);
110
    }
111
}
112