DataListener   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A kernelView() 0 18 4
1
<?php
2
3
namespace App\EventListener\Submission\Validation;
4
5
use ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Core\Bridge\...ion\ValidationException 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...
6
use App\Service\SubmissionService;
7
use App\Entity\Submission;
8
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...orControllerResultEvent 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...
9
use Symfony\Component\Validator\ConstraintViolationList;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Valida...ConstraintViolationList 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...
10
11
/**
12
 * Class DataListener
13
 */
14
final class DataListener
15
{
16
    /**
17
     * @var \App\Service\SubmissionService
18
     */
19
    private $submissionService;
20
21
    /**
22
     * Constructor
23
     *
24
     * @param \App\Service\SubmissionService $submissionService
25
     */
26
    public function __construct(SubmissionService $submissionService)
27
    {
28
        $this->submissionService = $submissionService;
29
    }
30
31
    /**
32
     * Validate the submission data using the formio dryrun
33
     *
34
     * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
35
     */
36
    public function kernelView(GetResponseForControllerResultEvent $event)
37
    {
38
        $request = $event->getRequest();
39
40
        if ($request->attributes->get('_api_resource_class') !== Submission::class) {
41
            return;
42
        }
43
44
        if ('post' !== $request->attributes->get('_api_collection_operation_name')) {
45
            return;
46
        }
47
48
        $submission = $event->getControllerResult();
49
        $violations = [];
50
51
        if (!$this->submissionService->isValid($submission, $violations)) {
52
            $list = new ConstraintViolationList($violations);
53
            throw new ValidationException($list, 'An error occurred');
54
        }
55
    }
56
}
57