HasEntrypointLookup   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 12
c 2
b 0
f 1
dl 0
loc 32
ccs 8
cts 14
cp 0.5714
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntrypointLookup() 0 3 1
A getWebpackCssFiles() 0 4 1
A hasEntrypoint() 0 8 3
A getWebpackJsFiles() 0 4 1
1
<?php
2
3
namespace ByTIC\Assets\AssetsManager;
4
5
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
6
7
/**
8
 * Trait HasEntrypointLookup
9
 * @package ByTIC\Assets\AssetsManager
10
 */
11
trait HasEntrypointLookup
12
{
13 1
    protected function getEntrypointLookup(string $entrypointName): EntrypointLookupInterface
14
    {
15 1
        return $this->getContainer()->get('assets.entrypoint_lookup')->getEntrypointLookup($entrypointName);
0 ignored issues
show
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        return $this->/** @scrutinizer ignore-call */ getContainer()->get('assets.entrypoint_lookup')->getEntrypointLookup($entrypointName);
Loading history...
16
    }
17
18
    /**
19
     * @param string $entrypointName
20
     * @return bool|false
21
     */
22
    public function hasEntrypoint(string $entryName, string $entrypointName = '_default')
23
    {
24
        try {
25
            $files = $this->getEntrypointLookup($entrypointName)->getJavaScriptFiles($entryName);
26
            $this->getEntrypointLookup($entrypointName)->reset();
27
            return is_array($files) && count($files);
28
        } catch (\Exception $e) {
29
            return false;
30
        }
31
    }
32
33 1
    public function getWebpackJsFiles(string $entryName, string $entrypointName = '_default'): array
34
    {
35 1
        return $this->getEntrypointLookup($entrypointName)
36 1
            ->getJavaScriptFiles($entryName);
37
    }
38
39 1
    public function getWebpackCssFiles(string $entryName, string $entrypointName = '_default'): array
40
    {
41 1
        return $this->getEntrypointLookup($entrypointName)
42 1
            ->getCssFiles($entryName);
43
    }
44
}
45