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 — static-map ( 1bc0cf )
by Eric
64:02
created

StaticSubscriber::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 3
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\Image;
13
14
use Ivory\GoogleMap\Helper\Event\StaticMapEvents;
15
use Ivory\GoogleMap\Helper\Subscriber\DelegateSubscriberInterface;
16
use Symfony\Component\EventDispatcher\Event;
17
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
class StaticSubscriber implements DelegateSubscriberInterface
23
{
24
    /**
25
     * @param Event                    $event
26
     * @param string                   $eventName
27
     * @param EventDispatcherInterface $eventDispatcher
28
     */
29 View Code Duplication
    public function handle(Event $event, $eventName, EventDispatcherInterface $eventDispatcher)
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...
30
    {
31
        $delegates = static::getDelegatedSubscribedEvents();
32
33
        if (isset($delegates[$eventName])) {
34
            foreach ($delegates[$eventName] as $delegate) {
35
                $eventDispatcher->dispatch($delegate, $event);
36
            }
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 View Code Duplication
    public static function getSubscribedEvents()
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...
44
    {
45
        $events = [];
46
47
        foreach (array_keys(static::getDelegatedSubscribedEvents()) as $event) {
48
            $events[$event] = 'handle';
49
        }
50
51
        return $events;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public static function getDelegatedSubscribedEvents()
58
    {
59
        return [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(\Ivory\Goog...StaticMapEvents::KEY)); (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...
60
            StaticMapEvents::HTML => [
61
                StaticMapEvents::CENTER,
62
                StaticMapEvents::FORMAT,
63
                StaticMapEvents::SCALE,
64
                StaticMapEvents::SIZE,
65
                StaticMapEvents::TYPE,
66
                StaticMapEvents::VISIBLE,
67
                StaticMapEvents::ZOOM,
68
                StaticMapEvents::MARKER,
69
                StaticMapEvents::POLYLINE,
70
                StaticMapEvents::ENCODED_POLYLINE,
71
                StaticMapEvents::KEY,
72
            ],
73
        ];
74
    }
75
}
76