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.

SimpleXMLElement::addChildCData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Bhaktaraz\RSSGenerator;
4
5
use SimpleXMLElement as XMLElement;
6
7
class SimpleXMLElement extends XMLElement
8
{
9
10
    /**
11
     * @param string $name
12
     * @param string $value
13
     * @param string $namespace
14
     * @return XMLElement
15
     */
16
    public function addChild($name, $value = null, $namespace = null)
17
    {
18
        if ($value !== null and is_string($value) === true) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
19
            $value = str_replace('&', '&amp;', $value);
20
        }
21
22
        return parent::addChild($name, $value, $namespace);
23
    }
24
25
    /**
26
     * Create a child with CDATA value
27
     * @param string $name The name of the child element to add.
28
     * @param string $cdata_text The CDATA value of the child element.
29
     */
30
    public function addChildCData($name, $cdata_text)
31
    {
32
        $child = $this->addChild($name);
33
        $child->addCData($cdata_text);
34
    }
35
36
    /**
37
     * Add CDATA text in a node
38
     * @param string $cdata_text The CDATA value  to add
39
     */
40
    private function addCData($cdata_text)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
41
    {
42
        $node = dom_import_simplexml($this);
43
        $no = $node->ownerDocument;
44
        $node->appendChild($no->createCDATASection($cdata_text));
45
    }
46
}
47