GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CrawlerTools::getNodeHtml()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0008

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 16
cts 17
cp 0.9412
rs 9.456
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0008
1
<?php
2
/*
3
 * This file is part of the trefoil application.
4
 *
5
 * (c) Miguel Angel Gabriel <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Trefoil\Util;
11
12
use Symfony\Component\DomCrawler\Crawler;
13
14
/**
15
 * Serveral utility operations for Crawler objects.
16
 *
17
 */
18
class CrawlerTools
19
{
20
21
    /**
22
     * Return the node name
23
     *
24
     * @param Crawler $node
25
     *
26
     * @return string
27
     */
28 1
    public static function getNodeName(Crawler $node)
29
    {
30 1
        return $node->getNode(0)->nodeName;
31
    }
32
33
    /**
34
     * Return the node text contents (w/o the children).
35
     *
36
     * @param Crawler $node
37
     *
38
     * @return string
39
     */
40
    public static function getNodeText(Crawler $node)
41
    {
42
        foreach ($node->getNode(0)->childNodes as $cNode) {
43
            if ("#text" == $cNode->nodeName) {
44
                return $cNode->nodeValue;
45
            }
46
        }
47
48
        return '';
49
    }
50
51
    /**
52
     * Return the node HTML contents
53
     *
54
     * @param Crawler $node
55
     *
56
     * @return string
57
     */
58 1
    public static function getNodeHtml(Crawler $node)
59
    {
60 1
        $domNode = $node->getNode(0);
61
62 1
        if (null === $domNode) {
63
            return '';
64
        }
65
66 1
        $html = $domNode->ownerDocument->saveHtml($domNode);
67
68
        // remove line breaks
69 1
        $html = str_replace(array("\n", "\r"), '', $html);
70
71
        // remove surrounding tag
72 1
        $regExp = '/';
73 1
        $regExp .= '<(?<tag>.*)>';
74 1
        $regExp .= '(?<html>.*)$';
75 1
        $regExp .= '/Ums'; // Ungreedy, multiline, dotall
76
77 1
        $html = preg_replace_callback(
78 1
            $regExp,
79 1
            function ($matches) {
80 1
                return '<' . $matches['tag'] . '>' . $matches['html'];
81 1
            },
82
            $html
83 1
        );
84
85 1
        return $html;
86
    }
87
}
88