PluginLink   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 25.93 %

Importance

Changes 0
Metric Value
dl 7
loc 27
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 2
A process() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}