Completed
Pull Request — develop (#72)
by
unknown
07:04
created

PlayerChartValueSubscriber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getSubscribedEvents() 0 4 1
A setValue() 0 11 4
1
<?php
2
namespace VideoGamesRecords\CoreBundle\EventSubscriber;
3
4
use ApiPlatform\Core\EventListener\EventPriorities;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Core\EventListener\EventPriorities was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use VideoGamesRecords\CoreBundle\Entity\PlayerChart;
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\KernelEvents;
9
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
10
11
final class PlayerChartValueSubscriber implements EventSubscriberInterface
12
{
13
14
    public function __construct()
15
    {
16
    }
17
18
    public static function getSubscribedEvents()
19
    {
20
        return [
21
            KernelEvents::VIEW => ['setValue', EventPriorities::POST_VALIDATE],
22
        ];
23
    }
24
25
    /**
26
     * @param GetResponseForControllerResultEvent $event
27
     */
28
    public function setValue(GetResponseForControllerResultEvent $event)
29
    {
30
        $playerChart = $event->getControllerResult();
31
        $method = $event->getRequest()->getMethod();
32
33
        if (!$playerChart instanceof PlayerChart || Request::METHOD_PUT !== $method) {
34
            return;
35
        }
36
37
        foreach ($playerChart->getLibs() as $lib) {
38
            $lib->setValueFromPaseValue();
39
        }
40
    }
41
}
42