Completed
Push — 2.0 ( adbaaa...97f48a )
by Nicolas
16:50
created

AssetsViewComposer::onBackend()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 8
loc 8
rs 9.4285
1
<?php namespace Modules\Core\Composers;
2
3
use Illuminate\Contracts\View\View;
4
use Illuminate\Http\Request;
5
use Modules\Core\Foundation\Asset\Manager\AssetManager;
6
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
7
use Modules\Core\Foundation\Asset\Types\AssetTypeFactory;
8
9
class AssetsViewComposer
10
{
11
    /**
12
     * @var AssetManager
13
     */
14
    protected $assetManager;
15
    /**
16
     * @var AssetPipeline
17
     */
18
    protected $assetPipeline;
19
    /**
20
     * @var AssetTypeFactory
21
     */
22
    protected $assetFactory;
23
    /**
24
     * @var Request
25
     */
26
    private $request;
27
28
    public function __construct(AssetManager $assetManager, AssetPipeline $assetPipeline, AssetTypeFactory $assetTypeFactory, Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
29
    {
30
        $this->assetManager = $assetManager;
31
        $this->assetPipeline = $assetPipeline;
32
        $this->assetFactory = $assetTypeFactory;
33
        $this->request = $request;
34
    }
35
36
    public function compose(View $view)
37
    {
38
        if ($this->onBackend() === false) {
39
            return;
40
        }
41
        $this->requireDefaultAssets();
42
43
        $view->with('cssFiles', $this->assetPipeline->allCss());
44
        $view->with('jsFiles', $this->assetPipeline->allJs());
45
    }
46
47
    /**
48
     * Require the default assets from config file on the asset pipeline
49
     */
50
    private function requireDefaultAssets()
51
    {
52
        $this->assetPipeline->requireCss(config('asgard.core.core.admin-required-assets.css'));
53
        $this->assetPipeline->requireJs(config('asgard.core.core.admin-required-assets.js'));
54
    }
55
56 View Code Duplication
    private function onBackend()
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...
57
    {
58
        $url = $this->request->url();
59
        if (str_contains($url, config('asgard.core.core.admin-prefix'))) {
60
            return true;
61
        }
62
        return false;
63
    }
64
}
65