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.

ResponseCreationListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ma27\ApiKeyAuthenticationBundle\EventListener;
4
5
use Ma27\ApiKeyAuthenticationBundle\Event\OnAssembleResponseEvent;
6
use Ma27\ApiKeyAuthenticationBundle\Ma27ApiKeyAuthenticationEvents;
7
use Ma27\ApiKeyAuthenticationBundle\Service\Mapping\ClassMetadata;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Symfony\Component\Translation\TranslatorInterface;
11
12
/**
13
 * ResponseCreationListener.
14
 *
15
 * Default listener which assembles the response for the API key request.
16
 */
17
class ResponseCreationListener implements EventSubscriberInterface
18
{
19
    /**
20
     * @var TranslatorInterface
21
     */
22
    private $translator;
23
24
    /**
25
     * @var ClassMetadata
26
     */
27
    private $metadata;
28
29
    /**
30
     * @var string
31
     */
32
    private $apiKeyValue;
33
34
    /**
35
     * @var string
36
     */
37
    private $messageValue;
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param TranslatorInterface $translator
43
     * @param ClassMetadata       $classMetadata
44
     * @param array               $resultConfig
45
     */
46 14
    public function __construct(TranslatorInterface $translator, ClassMetadata $classMetadata, array $resultConfig)
47
    {
48 14
        $this->translator = $translator;
49 14
        $this->metadata = $classMetadata;
50 14
        $this->apiKeyValue = $resultConfig['api_key_property'];
51 14
        $this->messageValue = $resultConfig['error_property'];
52 14
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 16
    public static function getSubscribedEvents()
58
    {
59 16
        return array(Ma27ApiKeyAuthenticationEvents::ASSEMBLE_RESPONSE => array(
60
            array('onResponseCreation', -10),
61
        ));
62
    }
63
64
    /**
65
     * Assembles the response.
66
     *
67
     * @param OnAssembleResponseEvent $event
68
     */
69 14
    public function onResponseCreation(OnAssembleResponseEvent $event)
70
    {
71 14
        if ($event->isSuccess()) {
72 9
            $event->setResponse(new JsonResponse(array(
73 9
                $this->apiKeyValue => $this->metadata->getPropertyValue($event->getUser(), ClassMetadata::API_KEY_PROPERTY),
0 ignored issues
show
Bug introduced by
It seems like $event->getUser() targeting Ma27\ApiKeyAuthenticatio...esponseEvent::getUser() can also be of type null; however, Ma27\ApiKeyAuthenticatio...ata::getPropertyValue() does only seem to accept object, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
74
            )));
75
76 9
            return;
77
        }
78
79 5
        $event->setResponse(new JsonResponse(
80 5
            array($this->messageValue => $this->translator->trans($event->getException()->getMessage() ?: 'Credentials refused!')),
81 5
            JsonResponse::HTTP_UNAUTHORIZED
82
        ));
83 5
    }
84
}
85