Asset   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 6
eloc 10
c 3
b 1
f 1
dl 0
loc 35
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 2
A isExists() 0 3 1
A write() 0 3 1
A __construct() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
namespace gulch\Assets;
4
5
use gulch\Assets\Contract\RendererInterface;
6
7
class Asset
8
{
9
    /** @var RendererInterface */
10
    private $renderer;
11
12
    /** @var array */
13
    private $assets = [];
14
15
    public function __construct(RendererInterface $renderer)
16
    {
17
        $this->renderer = $renderer;
18
    }
19
20
    public function add(string $asset): self
21
    {
22
        if (!$this->isExists($asset)) {
23
            $this->assets[] = $asset;
24
        }
25
26
        return $this;
27
    }
28
29
    public function write(): string
30
    {
31
        return $this->renderer->render($this->assets);
32
    }
33
34
    public function __toString()
35
    {
36
        return $this->write();
37
    }
38
39
    private function isExists(string $asset): bool
40
    {
41
        return \in_array($asset, $this->assets, true);
42
    }
43
}
44