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.

ValidatorDescriptor::buildArgValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1
Metric Value
dl 6
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * @link https://github.com/old-town/old-town-workflow
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Workflow\Loader;
7
8
use DOMElement;
9
use DOMDocument;
10
use OldTown\Workflow\Exception\InvalidDescriptorException;
11
use OldTown\Workflow\Exception\InvalidWriteWorkflowException;
12
13
/**
14
 * Class ConditionDescriptor
15
 *
16
 * @package OldTown\Workflow\Loader
17
 */
18 View Code Duplication
class ValidatorDescriptor extends AbstractDescriptor
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
19
    implements Traits\ArgsInterface,
20
               Traits\TypeInterface,
21
               Traits\NameInterface,
22
               Traits\CustomArgInterface,
23
               WriteXmlInterface
24
{
25
    use Traits\ArgsTrait, Traits\TypeTrait, Traits\IdTrait, Traits\NameTrait;
26
27
    /**
28
     * @param $element
29
     */
30 15
    public function __construct(DOMElement $element = null)
31
    {
32 15
        parent::__construct($element);
33
34 15
        if (null !== $element) {
35 12
            $this->init($element);
36 12
        }
37 15
    }
38
39
    /**
40
     * @param DOMElement $element
41
     *
42
     * @return void
43
     */
44 12
    protected function init(DOMElement $element)
45
    {
46 12
        $this->parseType($element);
47 12
        $this->parseId($element, false);
48 12
        $this->parseName($element, false);
49
50 12
        $this->parseArgs($element);
51 12
    }
52
53
54
    /**
55
     * Создает DOMElement - эквивалентный состоянию дескриптора
56
     *
57
     * @param DOMDocument $dom
58
     *
59
     * @return DOMElement
60
     * @throws InvalidDescriptorException
61
     * @throws \OldTown\Workflow\Exception\InvalidWriteWorkflowException
62
     */
63 7
    public function writeXml(DOMDocument $dom = null)
64
    {
65 7
        if (null === $dom) {
66 1
            $errMsg = 'Не передан DOMDocument';
67 1
            throw new InvalidWriteWorkflowException($errMsg);
68
        }
69 6
        $descriptor = $dom->createElement('validator');
70
71
72 6
        if ($this->hasId()) {
73 5
            $id = $this->getId();
74 5
            $descriptor->setAttribute('id', $id);
75 5
        }
76
77 6
        $name = $this->getName();
78 6
        if (null !== $name) {
79 5
            $nameEncode = XmlUtil::encode($name);
80 5
            $descriptor->setAttribute('name', $nameEncode);
81 5
        }
82
83 6
        $type = $this->getType();
84 6
        if (null === $type) {
85 1
            $errMsg = 'Некорректное значение для атрибута type';
86 1
            throw new InvalidDescriptorException($errMsg);
87
        }
88
89 5
        $descriptor->setAttribute('type', $type);
90
91 5
        $this->writeArgs($descriptor);
92
93 5
        return $descriptor;
94
    }
95
96
97
    /**
98
     * @param string $key
99
     * @param string $value
100
     *
101
     * @return boolean
102
     */
103 5
    public function flagUseCustomArgWriter($key, $value)
104
    {
105 5
        $flag = 'phpshell' === $this->getType();
106
107 5
        return $flag;
108
    }
109
110
    /**
111
     * Генерирует значение аргумента
112
     *
113
     * @param            $key
114
     * @param            $value
115
     *
116
     * @param DOMElement $argElement
117
     *
118
     * @return string
119
     */
120 4
    public function buildArgValue($key, $value, DOMElement $argElement)
121
    {
122 4
        $dom = $argElement->ownerDocument;
123 4
        $argValueElement = $dom->createCDATASection($value);
124 4
        $argElement->appendChild($argValueElement);
125 4
    }
126
}
127