ScoreSetValueSubscriber   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A __construct() 0 2 1
A setValue() 0 10 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\EventSubscriber;
6
7
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...
8
use ApiPlatform\Symfony\EventListener\EventPriorities as EventPrioritiesAlias;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpKernel\Event\ViewEvent;
12
use Symfony\Component\HttpKernel\KernelEvents;
13
use VideoGamesRecords\CoreBundle\Entity\PlayerChart;
14
use VideoGamesRecords\CoreBundle\Entity\PlayerChartLib;
15
16
final class ScoreSetValueSubscriber implements EventSubscriberInterface
17
{
18
    public function __construct()
19
    {
20
    }
21
22
    public static function getSubscribedEvents(): array
23
    {
24
        return [
25
            KernelEvents::VIEW => ['setValue', EventPrioritiesAlias::POST_VALIDATE],
26
        ];
27
    }
28
29
    /**
30
     * @param ViewEvent $event
31
     */
32
    public function setValue(ViewEvent $event): void
33
    {
34
        $playerChart = $event->getControllerResult();
35
        $method = $event->getRequest()->getMethod();
36
37
        if (($playerChart instanceof PlayerChart)
38
            && in_array($method, array(Request::METHOD_POST, Request::METHOD_PUT))) {
39
            /** @var PlayerChartLib $lib */
40
            foreach ($playerChart->getLibs() as $lib) {
41
                $lib->setValueFromPaseValue();
42
            }
43
        }
44
    }
45
}
46