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 ( f79bcb...de7e43 )
by Eric
80:29 queued 77:22
created

ApiJavascriptSubscriber::getApiRenderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Helper\Subscriber;
13
14
use Ivory\GoogleMap\Helper\Event\ApiEvent;
15
use Ivory\GoogleMap\Helper\Event\ApiEvents;
16
use Ivory\GoogleMap\Helper\Formatter\Formatter;
17
use Ivory\GoogleMap\Helper\Renderer\ApiRenderer;
18
use Ivory\GoogleMap\Helper\Renderer\Html\JavascriptTagRenderer;
19
use Symfony\Component\EventDispatcher\Event;
20
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
21
22
/**
23
 * @author GeLo <[email protected]>
24
 */
25
class ApiJavascriptSubscriber extends AbstractDelegateSubscriber
26
{
27
    /**
28
     * @var ApiRenderer
29
     */
30
    private $apiRenderer;
31
32
    /**
33
     * @var JavascriptTagRenderer
34
     */
35
    private $javascriptTagRenderer;
36
37
    /**
38
     * @param Formatter             $formatter
39
     * @param ApiRenderer           $apiRenderer
40
     * @param JavascriptTagRenderer $javascriptTagRenderer
41
     */
42 268
    public function __construct(
43
        Formatter $formatter,
44
        ApiRenderer $apiRenderer,
45
        JavascriptTagRenderer $javascriptTagRenderer
46
    ) {
47 268
        parent::__construct($formatter);
48
49 268
        $this->setApiRenderer($apiRenderer);
50 268
        $this->setJavascriptTagRenderer($javascriptTagRenderer);
51 268
    }
52
53
    /**
54
     * @return ApiRenderer
55
     */
56 264
    public function getApiRenderer()
57
    {
58 264
        return $this->apiRenderer;
59
    }
60
61
    /**
62
     * @param ApiRenderer $apiRenderer
63
     */
64 268
    public function setApiRenderer(ApiRenderer $apiRenderer)
65
    {
66 268
        $this->apiRenderer = $apiRenderer;
67 268
    }
68
69
    /**
70
     * @return JavascriptTagRenderer
71
     */
72 264
    public function getJavascriptTagRenderer()
73
    {
74 264
        return $this->javascriptTagRenderer;
75
    }
76
77
    /**
78
     * @param JavascriptTagRenderer $javascriptTagRenderer
79
     */
80 268
    public function setJavascriptTagRenderer(JavascriptTagRenderer $javascriptTagRenderer)
81
    {
82 268
        $this->javascriptTagRenderer = $javascriptTagRenderer;
83 268
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 264
    public function handle(Event $event, $eventName, EventDispatcherInterface $eventDispatcher)
89
    {
90 264
        parent::handle($event, $eventName, $eventDispatcher);
91
92 264
        if ($event instanceof ApiEvent) {
93 264
            $this->handleApi($event);
94 132
        }
95 264
    }
96
97
    /**
98
     * @return string[][]
99
     */
100 268
    public static function getDelegatedSubscribedEvents()
101
    {
102
        return [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(\Ivory\Goog...ASCRIPT_AUTOCOMPLETE)); (array<*,array>) is incompatible with the return type declared by the interface Ivory\GoogleMap\Helper\S...legatedSubscribedEvents of type string[][].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
103 268
            ApiEvents::JAVASCRIPT => [
104 268
                ApiEvents::JAVASCRIPT_MAP,
105 268
                ApiEvents::JAVASCRIPT_AUTOCOMPLETE,
106 134
            ],
107 134
        ];
108
    }
109
110
    /**
111
     * @param ApiEvent $event
112
     */
113 264
    private function handleApi(ApiEvent $event)
114
    {
115 264
        $event->setCode($this->getJavascriptTagRenderer()->render($this->getApiRenderer()->render(
116 264
            $event->getCallbacks(),
117 264
            $event->getRequirements(),
118 264
            $event->getSources(),
119 264
            $event->getLibraries()
120 132
        )));
121 264
    }
122
}
123