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
Push — master ( 5265cb...c87b3e )
by Tomasz
02:12
created

ShortcodeFacade::setParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
namespace Thunder\Shortcode;
3
4
use Thunder\Shortcode\EventContainer\EventContainer;
5
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
6
use Thunder\Shortcode\HandlerContainer\HandlerContainerInterface;
7
use Thunder\Shortcode\Parser\ParserInterface;
8
use Thunder\Shortcode\Parser\RegularParser;
9
use Thunder\Shortcode\Processor\Processor;
10
use Thunder\Shortcode\Processor\ProcessorInterface;
11
use Thunder\Shortcode\Serializer\JsonSerializer;
12
use Thunder\Shortcode\Serializer\SerializerInterface;
13
use Thunder\Shortcode\Serializer\TextSerializer;
14
use Thunder\Shortcode\Serializer\XmlSerializer;
15
use Thunder\Shortcode\Serializer\YamlSerializer;
16
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
17
use Thunder\Shortcode\Syntax\CommonSyntax;
18
use Thunder\Shortcode\Syntax\SyntaxInterface;
19
20
/**
21
 * @author Tomasz Kowalczyk <[email protected]>
22
 */
23
class ShortcodeFacade
24
{
25
    /** @var ProcessorInterface */
26
    private $processor;
27
    /** @var ParserInterface */
28
    private $parser;
29
    /** @var SyntaxInterface */
30
    private $syntax;
31
32
    /** @var HandlerContainer */
33
    private $handlers;
34
    /** @var EventContainer */
35
    private $events;
36
37
    /** @var SerializerInterface */
38
    private $textSerializer;
39
    /** @var SerializerInterface */
40
    private $jsonSerializer;
41
    /** @var SerializerInterface */
42
    private $xmlSerializer;
43
    /** @var SerializerInterface */
44
    private $yamlSerializer;
45
46 5
    public function __construct()
47
    {
48 5
        $this->syntax = new CommonSyntax();
49 5
        $this->handlers = new HandlerContainer();
50 5
        $this->events = new EventContainer();
51
52 5
        $this->parser = new RegularParser($this->syntax);
53 5
        $this->rebuildProcessor();
54
55 5
        $this->textSerializer = new TextSerializer();
56 5
        $this->jsonSerializer = new JsonSerializer();
57 5
        $this->yamlSerializer = new YamlSerializer();
58 5
        $this->xmlSerializer = new XmlSerializer();
59 5
    }
60
61
    /** @deprecated use constructor and customize using exposed methods */
62 1
    public static function create(HandlerContainerInterface $handlers, SyntaxInterface $syntax)
63
    {
64 1
        $self = new self();
65
66 1
        $self->handlers = $handlers;
0 ignored issues
show
Documentation Bug introduced by
$handlers is of type object<Thunder\Shortcode...dlerContainerInterface>, but the property $handlers was declared to be of type object<Thunder\Shortcode...ainer\HandlerContainer>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
67 1
        $self->syntax = $syntax;
68 1
        $self->rebuildProcessor();
69
70 1
        return $self;
71
    }
72
73 5
    private function rebuildProcessor()
74
    {
75 5
        $this->processor = new Processor($this->parser, $this->handlers);
76 5
        $this->processor = $this->processor->withEventContainer($this->events);
77 5
    }
78
79 2
    public function process($text)
80
    {
81 2
        return $this->processor->process($text);
82
    }
83
84 1
    public function parse($text)
85
    {
86 1
        return $this->parser->parse($text);
87
    }
88
89 1
    public function setParser(ParserInterface $parser)
90
    {
91 1
        $this->parser = $parser;
92 1
        $this->rebuildProcessor();
93
94 1
        return $this;
95
    }
96
97 2
    public function addHandler($name, $handler)
98
    {
99 2
        $this->handlers->add($name, $handler);
100
101 2
        return $this;
102
    }
103
104 1
    public function addHandlerAlias($alias, $name)
105
    {
106 1
        $this->handlers->addAlias($alias, $name);
107
108 1
        return $this;
109
    }
110
111 1
    public function addEventHandler($name, $handler)
112
    {
113 1
        $this->events->addListener($name, $handler);
114
115 1
        return $this;
116
    }
117
118
    /* --- SERIALIZATION --------------------------------------------------- */
119
120 2 View Code Duplication
    public function serialize(ShortcodeInterface $shortcode, $format)
0 ignored issues
show
Duplication introduced by
This method 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...
121
    {
122
        switch($format) {
123 2
            case 'text': return $this->textSerializer->serialize($shortcode);
124 2
            case 'json': return $this->jsonSerializer->serialize($shortcode);
125 2
            case 'yaml': return $this->yamlSerializer->serialize($shortcode);
126 2
            case 'xml': return $this->xmlSerializer->serialize($shortcode);
127 1
            default: throw new \InvalidArgumentException(sprintf('Invalid serialization format %s!', $format));
128 1
        }
129
    }
130
131 2 View Code Duplication
    public function unserialize($text, $format)
0 ignored issues
show
Duplication introduced by
This method 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...
132
    {
133
        switch($format) {
134 2
            case 'text': return $this->textSerializer->unserialize($text);
135 2
            case 'json': return $this->jsonSerializer->unserialize($text);
136 2
            case 'yaml': return $this->yamlSerializer->unserialize($text);
137 2
            case 'xml': return $this->xmlSerializer->unserialize($text);
138 1
            default: throw new \InvalidArgumentException(sprintf('Invalid unserialization format %s!', $format));
139 1
        }
140
    }
141
142
    /** @deprecated use serialize($shortcode, $format) */
143
    public function serializeToText(ShortcodeInterface $s) { return $this->serialize($s, 'text'); }
144
    /** @deprecated use serialize($shortcode, $format) */
145
    public function serializeToJson(ShortcodeInterface $s) { return $this->serialize($s, 'json'); }
146
    /** @deprecated use unserialize($shortcode, $format) */
147
    public function unserializeFromText($text) { return $this->unserialize($text, 'text'); }
148
    /** @deprecated use unserialize($shortcode, $format) */
149
    public function unserializeFromJson($text) { return $this->unserialize($text, 'json'); }
150
}
151