EntryPoint   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 59
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 1
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addFromWebpack() 0 12 3
A collection() 0 6 2
A styles() 0 3 1
A scripts() 0 3 1
A initCollection() 0 5 1
1
<?php
2
3
namespace ByTIC\Assets\Assets;
4
5
/**
6
 * Class EntryPoint
7
 * @package ByTIC\Assets\Assets
8
 */
9
class EntryPoint
10
{
11
    protected $collections = [];
12
13
    /**
14
     * @return AssetCollection
15
     */
16 2
    public function styles()
17
    {
18 2
        return $this->collection(Asset::TYPE_STYLES);
19
    }
20
21
    /**
22
     * @return AssetCollection
23
     */
24 2
    public function scripts()
25
    {
26 2
        return $this->collection(Asset::TYPE_SCRIPTS);
27
    }
28
29
    /**
30
     * @param $entryName
31
     * @noinspection PhpDocMissingThrowsInspection
32
     */
33 1
    public function addFromWebpack($entryName, $method = 'prepend')
34
    {
35
        /** @noinspection PhpUnhandledExceptionInspection */
36 1
        $scripts = assets_manager()->getWebpackJsFiles($entryName);
37 1
        foreach ($scripts as $script) {
38 1
            $this->scripts()->{$method}($script);
39
        }
40
41
        /** @noinspection PhpUnhandledExceptionInspection */
42 1
        $styles = assets_manager()->getWebpackCssFiles($entryName);
43 1
        foreach ($styles as $style) {
44 1
            $this->styles()->{$method}($style);
45
        }
46 1
    }
47
48
    /**
49
     * @param string $type
50
     * @return AssetCollection
51
     */
52 2
    public function collection($type)
53
    {
54 2
        if (!isset($this->collections[$type])) {
55 2
            $this->initCollection($type);
56
        }
57 2
        return $this->collections[$type];
58
    }
59
60
    /**
61
     * @param $type
62
     */
63 2
    protected function initCollection($type)
64
    {
65 2
        $collection = new AssetCollection();
66 2
        $collection->setAssetType($type);
67 2
        $this->collections[$type] = $collection;
68 2
    }
69
}
70