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 ( a69988...dd33d8 )
by Tomasz
12s
created

ShortcodeFacade::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 2
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
    public static function create(HandlerContainerInterface $handlers, SyntaxInterface $syntax)
63
    {
64
        $self = new self();
65
66
        $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
        $self->syntax = $syntax;
68
        $self->rebuildProcessor();
69
70
        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);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
124 2
            case 'json': return $this->jsonSerializer->serialize($shortcode);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
125 2
            case 'yaml': return $this->yamlSerializer->serialize($shortcode);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
126 2
            case 'xml': return $this->xmlSerializer->serialize($shortcode);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
127 1
            default: throw new \InvalidArgumentException(sprintf('Invalid serialization format %s!', $format));
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
135 2
            case 'json': return $this->jsonSerializer->unserialize($text);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
136 2
            case 'yaml': return $this->yamlSerializer->unserialize($text);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
137 2
            case 'xml': return $this->xmlSerializer->unserialize($text);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
138 1
            default: throw new \InvalidArgumentException(sprintf('Invalid unserialization format %s!', $format));
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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