Completed
Push — master ( b86345...d632d5 )
by Maxim
02:34
created

AbstractAsset::addAssetAfter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\mvc\assets;
4
5
abstract class AbstractAsset
6
{
7
8
    public $useLinks = true;
9
10
    public $publish = true;
11
12
    /** @var AbstractAsset[] */
13
    protected $assetsBefore = [];
14
15
    /** @var AbstractAsset[] */
16
    protected $assetsAfter = [];
17
18
    /**
19
     * @return string
20
     */
21
    abstract public function getBasePath(): string;
22
23
    /**
24
     * @return array
25
     */
26
    abstract public function css(): array;
27
28
    /**
29
     * @return array
30
     */
31
    abstract public function js(): array;
32
33
    /**
34
     * @return array
35
     */
36
    final public function internalCss(): array
37
    {
38
        return $this->getInternal($this->css());
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    final public function externalCss(): array
45
    {
46
        return $this->getExternal($this->css());
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    final public function internalJs(): array
53
    {
54
        return $this->getInternal($this->js());
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    final public function externalJs(): array
61
    {
62
        return $this->getExternal($this->js());
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getHash(): string
69
    {
70
        return \md5(static::class);
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getAssetsBefore(): array
77
    {
78
        return $this->assetsBefore;
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    public function getAssetsAfter(): array
85
    {
86
        return $this->assetsAfter;
87
    }
88
89
    /**
90
     * @param AbstractAsset $asset
91
     */
92
    public function addAssetBefore(AbstractAsset $asset)
93
    {
94
        $this->assetsBefore[\get_class($asset)] = $asset;
95
    }
96
97
    /**
98
     * @param AbstractAsset $asset
99
     */
100
    public function addAssetAfter(AbstractAsset $asset)
101
    {
102
        $this->assetsAfter[\get_class($asset)] = $asset;
103
    }
104
105
    /**
106
     * @param array $files
107
     *
108
     * @return array
109
     */
110 View Code Duplication
    private function getInternal(array $files): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        $result = [];
113
        foreach ($files as $file) {
114
            if ($this->isInternal($file)) {
115
                $result[] = $file;
116
            }
117
        }
118
        return $result;
119
    }
120
121
    /**
122
     * @param array $files
123
     *
124
     * @return array
125
     */
126 View Code Duplication
    private function getExternal(array $files): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        $result = [];
129
        foreach ($files as $file) {
130
            if (!$this->isInternal($file)) {
131
                $result[] = $file;
132
            }
133
        }
134
        return $result;
135
    }
136
137
    /**
138
     * @param string $file
139
     *
140
     * @return bool
141
     */
142
    private function isInternal(string $file): bool
143
    {
144
        return (false === \strpos($file, 'http') && false === \strpos($file, '//'));
145
    }
146
}
147