Completed
Push — master ( 422ca2...2d71c3 )
by Rémi
02:38
created

ApplicationUserListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 53
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 12 2
A isListener() 0 4 1
1
<?php
2
3
namespace MiniGameMessageApp\Listener;
4
5
use League\Event\EventInterface;
6
use League\Event\ListenerInterface;
7
use MiniGame\Event\PlayerCreatedEvent;
8
use MiniGameMessageApp\Finder\MiniGameUserFinder;
9
use Psr\Log\LoggerAwareInterface;
10
use Psr\Log\LoggerAwareTrait;
11
use Psr\Log\NullLogger;
12
13
class ApplicationUserListener implements ListenerInterface, LoggerAwareInterface
14
{
15
    use LoggerAwareTrait;
16
17
    /**
18
     * @var MiniGameUserFinder
19
     */
20
    private $finder;
21
22
    /**
23
     * Constructor
24
     *
25
     * @param MiniGameUserFinder $finder
26
     */
27
    public function __construct(
28
        MiniGameUserFinder $finder
29
    ) {
30
        $this->finder = $finder;
31
        $this->logger = new NullLogger();
32
    }
33
34
    /**
35
     * Handle an event.
36
     *
37
     * @param EventInterface $event
38
     *
39
     * @return void
40
     */
41
    public function handle(EventInterface $event)
42
    {
43
        if (! $event instanceof PlayerCreatedEvent) {
0 ignored issues
show
Bug introduced by
The class MiniGame\Event\PlayerCreatedEvent does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
44
            return;
45
        }
46
47
        $applicationUser = $this->finder->find($event->getExternalReference());
48
49
        $applicationUser->linkToPlayer($event->getGameId(), $event->getPlayerId());
50
51
        $this->finder->save($applicationUser);
52
    }
53
54
    /**
55
     * Check whether the listener is the given parameter.
56
     *
57
     * @param mixed $listener
58
     *
59
     * @return bool
60
     */
61
    public function isListener($listener)
62
    {
63
        return $this == $listener;
64
    }
65
}
66