Completed
Push — 2.0 ( 9eb0c1...f96b39 )
by Nicolas
03:28
created

AssetsViewComposer::requireDefaultAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Modules\Core\Composers;
4
5
use Illuminate\Contracts\View\View;
6
use Illuminate\Http\Request;
7
use Modules\Core\Foundation\Asset\Manager\AssetManager;
8
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
9
use Modules\Core\Foundation\Asset\Types\AssetTypeFactory;
10
11
class AssetsViewComposer
12
{
13
    /**
14
     * @var AssetManager
15
     */
16
    protected $assetManager;
17
    /**
18
     * @var AssetPipeline
19
     */
20
    protected $assetPipeline;
21
    /**
22
     * @var AssetTypeFactory
23
     */
24
    protected $assetFactory;
25
    /**
26
     * @var Request
27
     */
28
    private $request;
29
30
    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...
31
    {
32
        $this->assetManager = $assetManager;
33
        $this->assetPipeline = $assetPipeline;
34
        $this->assetFactory = $assetTypeFactory;
35
        $this->request = $request;
36
    }
37
38
    public function compose(View $view)
39
    {
40
        if ($this->onBackend() === false) {
41
            return;
42
        }
43
44
        $view->with('cssFiles', $this->assetPipeline->allCss());
45
        $view->with('jsFiles', $this->assetPipeline->allJs());
46
    }
47
48 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...
49
    {
50
        $url = $this->request->url();
51
        if (str_contains($url, config('asgard.core.core.admin-prefix'))) {
52
            return true;
53
        }
54
55
        return false;
56
    }
57
}
58