CreatePasteFormValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 3 1
A validate() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nastoletni\Code\Application\Form;
6
7
use Symfony\Component\Validator\Constraints as Assert;
8
use Symfony\Component\Validator\ConstraintViolationListInterface;
9
use Symfony\Component\Validator\Validation;
10
11
class CreatePasteFormValidator
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
12
{
13
    /**
14
     * Self fabric method just for convenience.
15
     *
16
     * @return CreatePasteFormValidator
17
     */
18 8
    public static function create(): CreatePasteFormValidator
19
    {
20 8
        return new static();
21
    }
22
23
    /**
24
     * CreatePasteValidator constructor.
25
     */
26 8
    private function __construct()
27
    {
28 8
    }
29
30
    /**
31
     * Validates given data to comply with entity requirements.
32
     *
33
     * @param array $data
34
     *
35
     * @return ConstraintViolationListInterface
36
     */
37 7
    public function validate(array $data): ConstraintViolationListInterface
38
    {
39 7
        $validator = Validation::createValidator();
40
41 7
        $constraint = new Assert\Collection([
42 7
            'title' => new Assert\NotNull(['message' => 'validator.title.not_null']),
43 7
            'name'  => new Assert\All([
44 7
                new Assert\NotNull(['message' => 'validator.name.not_null']),
45
            ]),
46 7
            'content' => new Assert\All([
47 7
                new Assert\NotBlank(['message' => 'validator.content.not_blank']),
48
            ]),
49
        ]);
50
51 7
        return $validator->validate($data, $constraint);
52
    }
53
}
54