Test Failed
Push — master ( f562c0...ed7d3a )
by Dominik
02:11
created

CourseMapping::getPropertyMappings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiSkeleton\Validation;
6
7
use Chubbyphp\Model\ResolverInterface;
8
use Chubbyphp\Validation\Constraint\ChoiceConstraint;
9
use Chubbyphp\Validation\Constraint\ConstraintInterface;
10
use Chubbyphp\Validation\Constraint\NotBlankConstraint;
11
use Chubbyphp\Validation\Constraint\NotNullConstraint;
12
use Chubbyphp\Validation\Constraint\NumericConstraint;
13
use Chubbyphp\Validation\Constraint\NumericRangeConstraint;
14
use Chubbyphp\Validation\Mapping\ObjectMappingInterface;
15
use Chubbyphp\Validation\Mapping\PropertyMapping;
16
use Chubbyphp\Validation\Mapping\PropertyMappingInterface;
17
use Chubbyphp\ApiSkeleton\Model\Course;
18
use Chubbyphp\ValidationModel\Constraint\UniqueModelConstraint;
19
20
final class CourseMapping implements ObjectMappingInterface
21
{
22
    /**
23
     * @var ResolverInterface
24
     */
25
    private $resolver;
26
27
    /**
28
     * @param ResolverInterface $resolver
29
     */
30
    public function __construct(ResolverInterface $resolver)
31
    {
32
        $this->resolver = $resolver;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getClass(): string
39
    {
40
        return Course::class;
41
    }
42
43
    /**
44
     * @return ConstraintInterface[]
45
     */
46
    public function getConstraints(): array
47
    {
48
        return [new UniqueModelConstraint($this->resolver, ['name'])];
49
    }
50
51
    /**
52
     * @return PropertyMappingInterface[]
53
     */
54
    public function getPropertyMappings(): array
55
    {
56
        return [
57
            new PropertyMapping('name', [new NotNullConstraint(), new NotBlankConstraint()]),
58
            new PropertyMapping('level', [
59
                new NotNullConstraint(),
60
                new ChoiceConstraint(
61
                    ChoiceConstraint::TYPE_INT,
62
                    Course::LEVEL
63
                ),
64
            ]),
65
            new PropertyMapping('progress', [
66
                new NotNullConstraint(),
67
                new NumericConstraint(),
68
                new NumericRangeConstraint(0, 1),
69
            ]),
70
            new PropertyMapping('active', [new NotNullConstraint(), new NotBlankConstraint()]),
71
        ];
72
    }
73
}
74