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.
Completed
Pull Request — master (#32)
by Tomasz
05:52
created

ProcessedShortcode::hasAncestor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
ccs 5
cts 5
cp 1
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
namespace Thunder\Shortcode\Shortcode;
3
4
use Thunder\Shortcode\Processor\ProcessorContext;
5
use Thunder\Shortcode\Processor\ProcessorInterface;
6
7
/**
8
 * @author Tomasz Kowalczyk <[email protected]>
9
 */
10
final class ProcessedShortcode extends AbstractShortcode implements ParsedShortcodeInterface
11
{
12
    /** @var ShortcodeInterface */
13
    private $parent;
14
    private $position;
15
    private $namePosition;
16
    private $text;
17
    private $textContent;
18
    private $offset;
19
    private $shortcodeText;
20
    private $iterationNumber;
21
    private $recursionLevel;
22
    /** @var ProcessorInterface */
23
    private $processor;
24
25 33
    private function __construct()
26
    {
27 33
    }
28
29 33
    public static function createFromContext(ProcessorContext $context)
30
    {
31 33
        $self = new self();
32
33
        // basic properties
34 33
        $self->name = $context->shortcode->getName();
35 33
        $self->parameters = $context->shortcode->getParameters();
36 33
        $self->content = $context->shortcode->getContent();
37 33
        $self->bbCode = $context->shortcode->getBbCode();
38 33
        $self->textContent = $context->textContent;
39
40
        // runtime context
41 33
        $self->parent = $context->parent;
42 33
        $self->position = $context->position;
43 33
        $self->namePosition = $context->namePosition[$self->name];
44 33
        $self->text = $context->text;
45 33
        $self->shortcodeText = $context->shortcodeText;
46
47
        // processor state
48 33
        $self->iterationNumber = $context->iterationNumber;
49 33
        $self->recursionLevel = $context->recursionLevel;
50 33
        $self->processor = $context->processor;
51
52
        // text context
53 33
        $self->offset = $context->offset;
54
55 33
        return $self;
56
    }
57
58 24
    public function withContent($content)
59
    {
60 24
        $self = clone $this;
61 24
        $self->content = $content;
62
63 24
        return $self;
64
    }
65
66 3
    public function hasAncestor($name)
67
    {
68 3
        $self = $this;
69
70
        while($self = $self->getParent()) {
71 2
            if($self->getName() === $name) {
72
                return true;
73 2
            }
74
        }
75
76 2
        return false;
77
    }
78 2
79
    public function getParent()
80
    {
81 2
        return $this->parent;
82
    }
83 2
84
    public function getTextContent()
85
    {
86 1
        return $this->textContent;
87
    }
88 1
89
    public function getPosition()
90
    {
91 1
        return $this->position;
92
    }
93 1
94
    public function getNamePosition()
95
    {
96 1
        return $this->namePosition;
97
    }
98 1
99
    public function getText()
100
    {
101 1
        return $this->text;
102
    }
103 1
104
    public function getShortcodeText()
105
    {
106 1
        return $this->shortcodeText;
107
    }
108 1
109
    public function getOffset()
110
    {
111 1
        return $this->offset;
112
    }
113 1
114
    public function getIterationNumber()
115
    {
116
        return $this->iterationNumber;
117
    }
118
119
    public function getRecursionLevel()
120
    {
121
        return $this->recursionLevel;
122
    }
123
124
    public function getProcessor()
125
    {
126
        return $this->processor;
127
    }
128
}
129