Passed
Push — master ( 9afe80...f5220c )
by Gabriel
03:51
created

AssetsServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\Assets;
4
5
use ByTIC\Assets\Encore\EntrypointLookupFactory;
6
use ByTIC\Assets\Encore\EntrypointsCollection;
7
use ByTIC\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
0 ignored issues
show
Bug introduced by
The type ByTIC\Container\ServiceP...ignatureServiceProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Asset\Package;
9
use Symfony\Component\Asset\Packages;
10
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
11
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection;
12
use Symfony\WebpackEncoreBundle\Asset\TagRenderer;
13
14
/**
15
 * Class AssetsServiceProvider
16
 * @package ByTIC\Assets
17
 */
18
class AssetsServiceProvider extends AbstractSignatureServiceProvider
19
{
20
    /**
21
     * @inheritDoc
22
     */
23
    public function provides()
24
    {
25
        return [
26
            'assets.manager',
27
            'assets.packages',
28
            'assets.tag_renderer',
29
            'assets.entrypoint_lookup',
30
        ];
31
    }
32
33
    public function register()
34
    {
35
        $this->registerManager();
36
        $this->registerPackages();
37
        $this->registerTagRenderer();
38
        $this->registerEntrypointLookupCollection();
39
    }
40
41
    protected function registerManager()
42
    {
43
        $this->getContainer()->share('assets.manager', function () {
44
            $manager = new AssetsManager();
45
            $manager->setContainer($this->getContainer());
46
            return $manager;
47
        });
48
    }
49
50
    protected function registerPackages()
51
    {
52
        $this->getContainer()->share('assets.packages', function () {
53
            $package = new Package(new EmptyVersionStrategy());
54
            return new Packages($package);
55
        });
56
    }
57
58
    protected function registerTagRenderer()
59
    {
60
        $this->getContainer()->share('assets.tag_renderer', function () {
61
            return new TagRenderer(
62
                $this->getContainer()->get('assets.entrypoint_lookup'),
63
                $this->getContainer()->get('assets.packages')
64
            );
65
        });
66
    }
67
68
    protected function registerEntrypointLookupCollection()
69
    {
70
        $this->getContainer()->share('assets.entrypoint_lookup', function () {
71
            return new EntrypointLookupCollection($this->generateBuildEntrypoints());
72
        });
73
    }
74
75
    /**
76
     * @return EntrypointsCollection
77
     */
78
    protected function generateBuildEntrypoints()
79
    {
80
        $entries = EntrypointLookupFactory::getBuilds();
81
        return new EntrypointsCollection($entries);
0 ignored issues
show
Bug introduced by
It seems like $entries can also be of type ByTIC\Config\Config; however, parameter $entries of ByTIC\Assets\Encore\Entr...llection::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

81
        return new EntrypointsCollection(/** @scrutinizer ignore-type */ $entries);
Loading history...
82
    }
83
}
84