Passed
Push — master ( 736032...f19203 )
by Gabriel
04:19 queued 30s
created

Asset   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 61.9%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 77
ccs 13
cts 21
cp 0.619
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A __construct() 0 5 1
A setType() 0 3 1
A getAttribs() 0 3 1
A setSource() 0 3 1
A getSource() 0 6 2
A setAttribs() 0 3 1
1
<?php
2
3
namespace ByTIC\Assets\Assets;
4
5
use ByTIC\Assets\Assets\Asset\AssetAttributes;
6
use ByTIC\Assets\Assets\Asset\AssetSource;
7
8
/**
9
 * Class Asset
10
 * @package ByTIC\Assets\Assets
11
 */
12
class Asset
13
{
14
    use Asset\Traits\CanRenderTrait;
15
    use Asset\Traits\HasContentTrait;
16
17
    const TYPE_STYLES = 'STYLES';
18
    const TYPE_SCRIPTS = 'SCRIPTS';
19
20
    /**
21
     * @var string
22
     */
23
    protected $type;
24
25
    protected $source = false;
26
    protected $attribs = [];
27
28
    /**
29
     * Asset constructor.
30
     * @param string $source
31
     * @param string $type
32
     */
33 9
    public function __construct(string $source = '', $type = '')
34
    {
35 9
        $this->source = AssetSource::check($source, $type);
36 9
        $this->type = $type;
37 9
        $this->attribs = AssetAttributes::defaultFor($type);
38 9
    }
39
40
    /**
41
     * @return string
42
     */
43 4
    public function getSource(): string
44
    {
45 4
        if ($this->source instanceof \Closure) {
0 ignored issues
show
introduced by
$this->source is never a sub-type of Closure.
Loading history...
46 4
            $this->source = ($this->source)();
47
        }
48 4
        return $this->source;
49
    }
50
51
    /**
52
     * @param string $source
53
     */
54
    public function setSource(string $source): void
55
    {
56
        $this->source = $source;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 4
    public function getType(): string
63
    {
64 4
        return $this->type;
65
    }
66
67
    /**
68
     * @param string $type
69
     */
70
    public function setType(string $type): void
71
    {
72
        $this->type = $type;
73
    }
74
75
    /**
76
     * @return array
77
     */
78 4
    public function getAttribs(): array
79
    {
80 4
        return $this->attribs;
81
    }
82
83
    /**
84
     * @param array $attribs
85
     */
86
    public function setAttribs(array $attribs): void
87
    {
88
        $this->attribs = $attribs;
89
    }
90
}