RelativeLink   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A process() 0 14 1
1
<?php
2
3
namespace Knp\MegaMAN\Markdown\Processor;
4
5
use Knp\MegaMAN\Markdown\Processor;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
8
9
class RelativeLink implements Processor
10
{
11
    /**
12
     * @var UrlGeneratorInterface
13
     */
14
    private $generator;
15
16
    /**
17
     * @var RequestStack
18
     */
19
    private $stack;
20
21
    /**
22
     * @param UrlGeneratorInterface $generator
23
     */
24
    public function __construct(UrlGeneratorInterface $generator, RequestStack $stack)
25
    {
26
        $this->generator = $generator;
27
        $this->stack     = $stack;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function process($html)
34
    {
35
        $request = $this->stack->getMasterRequest();
36
37
        $params = [
38
            'token'   => $request->attributes->get('token'),
39
            'panel'   => $request->query->get('panel'),
40
            'package' => $request->query->get('package'),
41
        ];
42
43
        $url = $this->generator->generate('_profiler', $params);
44
45
        return preg_replace('/<a([^>]*) href="(?!http|#)([^"]*)"/', sprintf('<a$1 href="%s&page=$2"', $url), $html);
46
    }
47
}
48