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   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 0
cbo 2
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 19 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