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.

PermissionDescriptor   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 1
cbo 7
dl 0
loc 90
ccs 40
cts 40
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A init() 0 11 2
A getRestriction() 0 4 1
B writeXml() 0 34 6
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
/**
15
 * Interface WorkflowDescriptor
16
 *
17
 * @package OldTown\Workflow\Loader
18
 */
19
class PermissionDescriptor extends AbstractDescriptor implements Traits\NameInterface, WriteXmlInterface
20
{
21
    use Traits\NameTrait, Traits\IdTrait;
22
23
    /**
24
     * @var RestrictionDescriptor
25
     */
26
    protected $restriction;
27
28
    /**
29
     * @param $element
30
     */
31 18
    public function __construct(DOMElement $element = null)
32
    {
33 18
        parent::__construct($element);
34
35 18
        if (null !== $element) {
36 16
            $this->init($element);
37 16
        }
38 18
    }
39
40
    /**
41
     * @param DOMElement $permission
42
     *
43
     * @return void
44
     */
45 16
    protected function init(DOMElement $permission)
46
    {
47 16
        $this->parseName($permission);
48 16
        $this->parseId($permission, false);
49
50
51 16
        $restrictTo = XMLUtil::getChildElement($permission, 'restrict-to');
52 16
        if ($restrictTo instanceof DOMElement) {
53 14
            $this->restriction = new RestrictionDescriptor($restrictTo);
54 14
        }
55 16
    }
56
57
    /**
58
     * @return RestrictionDescriptor
59
     */
60 15
    public function getRestriction()
61
    {
62 15
        return $this->restriction;
63
    }
64
65
    /**
66
     * Создает DOMElement - эквивалентный состоянию дескриптора
67
     *
68
     * @param DOMDocument $dom
69
     *
70
     * @return DOMElement|null
71
     * @throws InvalidDescriptorException
72
     * @throws InvalidWriteWorkflowException
73
     */
74 17
    public function writeXml(DOMDocument $dom = null)
75
    {
76 17
        if (null === $dom) {
77 1
            $errMsg = 'Не передан DOMDocument';
78 1
            throw new InvalidWriteWorkflowException($errMsg);
79
        }
80 16
        $descriptor = $dom->createElement('permission');
81
82 16
        if ($this->hasId()) {
83 2
            $id = $this->getId();
84 2
            $descriptor->setAttribute('id', $id);
85 2
        }
86 16
        $name = $this->getName();
87 16
        if (null === $name) {
88 1
            $errMsg = 'Некорректное значение для атрибута name';
89 1
            throw new InvalidDescriptorException($errMsg);
90
        }
91 15
        $descriptor->setAttribute('name', $name);
92
93
94 15
        $restriction = $this->getRestriction();
95 15
        if (null === $restriction) {
96 1
            $errMsg = 'Некорректное значение для restriction';
97 1
            throw new InvalidDescriptorException($errMsg);
98
        }
99 14
        $restrictionElement = $restriction->writeXml($dom);
100 14
        if (null === $restrictionElement) {
101 1
            $errMsg = 'Некорректное значение сгенерированного xml для restriction';
102 1
            throw new InvalidDescriptorException($errMsg);
103
        }
104 13
        $descriptor->appendChild($restrictionElement);
105
106 13
        return $descriptor;
107
    }
108
}
109