Asset::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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