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.

ModelElement::addElementToXml()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 3
eloc 10
nc 3
nop 3
1
<?php
2
3
namespace MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element;
4
5
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\XmlGeneratorException;
6
7
class ModelElement extends SimpleElementAbstract implements ConfigElementInterface
8
{
9
    /**
10
     * @param string $type
11
     * @return boolean
12
     */
13
    public function supports($type)
14
    {
15
        return $type === 'model';
16
    }
17
18
    /**
19
     * @param \SimpleXMLElement $xml
20
     * @param string $type
21
     * @param string $moduleName
22
     * @throws XmlGeneratorException
23
     * @return null
24
     */
25
    public function addElementToXml(\SimpleXMLElement $xml, $type, $moduleName)
26
    {
27
        $globalElements = $xml->xpath('/config/global');
28
29
        if (!count($globalElements)) {
30
            throw new XmlGeneratorException(sprintf('Global element not found in %s config file', $moduleName));
31
        }
32
33
        $modelsElement = $this->getElement($globalElements[0], 'models');
34
35
        $modelsClassContainer = $modelsElement->addChild(strtolower($moduleName));
36
        $modelsClassContainer->addChild('class', $moduleName . '_' . ucfirst($type));
37
38
        $resourceElementName = strtolower($moduleName).'_resource';
39
        if (count($modelsElement->xpath($resourceElementName))) {
40
            $modelsClassContainer->addChild('resourceModel', $resourceElementName);
41
        }
42
    }
43
}
44