PluginLink::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2017
4
 *
5
 * @package   Majima
6
 * @author    David Neustadt <[email protected]>
7
 * @copyright 2017 David Neustadt
8
 * @license   MIT
9
 */
10
11
namespace Dwoo\Plugins\Functions;
12
13
use Dwoo\Core;
14
use Dwoo\Plugin;
15
use Symfony\Component\DependencyInjection\Container;
16
17
/**
18
 * Class PluginLink
19
 */
20
class PluginLink extends Plugin
21
{
22
    /** @var Core */
23
    protected $core;
24
25
    /**
26
     * @var Container
27
     */
28
    private $container;
29
30 View Code Duplication
    public function __construct(Core $core)
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...
31
    {
32
        $this->core = $core;
33
        $globals = $core->getGlobals();
34
        $this->container = isset($globals['service_container']) ? $globals['service_container'] : null;
35
        parent::__construct($core);
36
    }
37
38
    public function process($path, $cacheBuster = null)
39
    {
40
        $baseUrl = $this->container->get('router')->getContext()->getBaseUrl();
41
        $url = $baseUrl . '/' . ltrim($path, '/');
42
        if ($cacheBuster) {
43
            $url .= '?' . $cacheBuster;
44
        }
45
46
        return $url;
47
    }
48
}