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.

SimpleElementAbstract   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 6
c 3
b 1
f 0
lcom 0
cbo 1
dl 0
loc 54
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A elementExistsInXml() 0 9 2
A addElementToXml() 0 12 2
A getElement() 0 10 2
1
<?php
2
3
namespace MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element;
4
5
6
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\XmlGeneratorException;
7
8
abstract class SimpleElementAbstract
9
{
10
    /**
11
     * @param \SimpleXMLElement $xml
12
     * @param string $type
13
     * @param string $moduleName
14
     * @return bool
15
     */
16
    public function elementExistsInXml(\SimpleXMLElement $xml, $type, $moduleName)
17
    {
18
        $targetElements = $xml->xpath('/config/global/'.$type.'s');
19
        if (!count($targetElements)) {
20
            return false;
21
        }
22
        $classElements = $xml->xpath('/config/global/'.$type.'s'.'/'.strtolower($moduleName).'/class');
23
        return (bool) count($classElements);
24
    }
25
26
    /**
27
     * @param \SimpleXMLElement $xml
28
     * @param string $type
29
     * @param string $moduleName
30
     * @throws XmlGeneratorException
31
     * @return null
32
     */
33
    public function addElementToXml(\SimpleXMLElement $xml, $type, $moduleName)
34
    {
35
        $globalElements = $xml->xpath('/config/global');
36
37
        if (!count($globalElements)) {
38
            throw new XmlGeneratorException(sprintf('Global element not found in %s config file', $moduleName));
39
        }
40
41
        $globalElements[0]->addChild($type.'s')
42
            ->addChild(strtolower($moduleName))
43
            ->addChild('class', $moduleName . '_' . ucfirst($type));
44
    }
45
46
    /**
47
     * @param \SimpleXMLElement $xml
48
     * @param string $path
49
     * @return \SimpleXMLElement
50
     */
51
    protected function getElement(\SimpleXMLElement $xml, $path)
52
    {
53
        $elements = $xml->xpath($path);
54
55
        if (!count($elements)) {
56
            return $xml->addChild($path);
57
        }
58
59
        return $elements[0];
60
    }
61
}