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   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 109
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 100%
Metric Value
wmc 10
lcom 2
cbo 8
dl 109
loc 109
ccs 41
cts 41
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A init() 8 8 1
B writeXml() 32 32 5
A flagUseCustomArgWriter() 6 6 1
A buildArgValue() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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