PrefixRelativeUrisRule   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B postRender() 0 26 5
1
<?php
2
3
namespace Kaloa\Renderer\Xml\Rule;
4
5
use DOMElement;
6
use Kaloa\Renderer\Xml\Rule\AbstractRule;
7
8
/**
9
 *
10
 */
11
final class PrefixRelativeUrisRule extends AbstractRule
12
{
13
    /**
14
     *
15
     * @var string
16
     */
17
    private $prefix;
18
19
    /**
20
     *
21
     * @param string $prefix
22
     */
23 1
    public function __construct($prefix = '')
24
    {
25 1
        $this->prefix = $prefix;
26 1
    }
27
28
    /**
29
     *
30
     */
31 1
    public function postRender()
32
    {
33 1
        $imageNodes = $this->runXpathQuery('//img[@src]');
34
35 1
        foreach ($imageNodes as $node) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
            /* @var $node DOMElement */
37 1
            $src = (string) $node->getAttribute('src');
38
39 1
            if (0 === preg_match('~^https?://|/~', $src)) {
40 1
                $src = $this->prefix . $src;
41 1
                $node->setAttribute('src', $src);
42 1
            }
43 1
        }
44
45 1
        $aNodes = $this->runXpathQuery('//a[@href]');
46
47 1
        foreach ($aNodes as $node) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
48
            /* @var $node DOMElement */
49 1
            $href = (string) $node->getAttribute('href');
50
51 1
            if (0 === preg_match('~^(https?://|mailto:|#|/)~', $href)) {
52 1
                $href = $this->prefix . $href;
53 1
                $node->setAttribute('href', $href);
54 1
            }
55 1
        }
56 1
    }
57
}
58