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 ( d8e85b...9135f5 )
by Tomasz
02:28
created

DeclareHandler::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 9.4285
cc 2
eloc 13
nc 2
nop 1
crap 2
1
<?php
2
namespace Thunder\Shortcode\Handler;
3
4
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
5
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
6
7
/**
8
 * @author Tomasz Kowalczyk <[email protected]>
9
 */
10
final class DeclareHandler
11
{
12
    /** @var HandlerContainer */
13
    private $handlers;
14
    private $delimiter;
15
16 17
    public function __construct(HandlerContainer $container, $delimiter = '%')
17
    {
18 17
        $this->handlers = $container;
19 17
        $this->delimiter = $delimiter;
20 17
    }
21
22
    /**
23
     * [declare name]Your name is %value%[/declare]
24
     * [name value="Thomas" /]
25
     *
26
     * @param ShortcodeInterface $shortcode
27
     */
28 3
    public function __invoke(ShortcodeInterface $shortcode)
29
    {
30 3
        $args = $shortcode->getParameters();
31 3
        if(empty($args)) {
32 1
            return;
33
        }
34 2
        $keys = array_keys($args);
35 2
        $name = array_shift($keys);
36 2
        $content = $shortcode->getContent();
37 2
        $delimiter = $this->delimiter;
38
39
        $this->handlers->add($name, function(ShortcodeInterface $shortcode) use($content, $delimiter) {
40 1
            $args = $shortcode->getParameters();
41
            $keys = array_map(function($key) use($delimiter) { return $delimiter.$key.$delimiter; }, array_keys($args));
42 1
            $values = array_values($args);
43
44 1
            return str_replace($keys, $values, $content);
45 2
        });
46 2
    }
47
}
48