Test Failed
Push — master ( ed7d3a...1e1c10 )
by Dominik
02:15
created

DocumentMapping::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
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\ConstraintInterface;
9
use Chubbyphp\Validation\Constraint\NotBlankConstraint;
10
use Chubbyphp\Validation\Constraint\NotNullConstraint;
11
use Chubbyphp\Validation\Mapping\ObjectMappingInterface;
12
use Chubbyphp\Validation\Mapping\PropertyMapping;
13
use Chubbyphp\Validation\Mapping\PropertyMappingInterface;
14
use Chubbyphp\ApiSkeleton\Model\Document;
15
use Chubbyphp\ValidationModel\Constraint\UniqueModelConstraint;
16
17
final class DocumentMapping implements ObjectMappingInterface
18
{
19
    /**
20
     * @var ResolverInterface
21
     */
22
    private $resolver;
23
24
    /**
25
     * @param ResolverInterface $resolver
26
     */
27
    public function __construct(ResolverInterface $resolver)
28
    {
29
        $this->resolver = $resolver;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getClass(): string
36
    {
37
        return Document::class;
38
    }
39
40
    /**
41
     * @return ConstraintInterface[]
42
     */
43
    public function getConstraints(): array
44
    {
45
        return [new UniqueModelConstraint($this->resolver, ['courseId', 'name'])];
46
    }
47
48
    /**
49
     * @return PropertyMappingInterface[]
50
     */
51
    public function getPropertyMappings(): array
52
    {
53
        return [
54
            new PropertyMapping('name', [new NotNullConstraint(), new NotBlankConstraint()]),
55
            new PropertyMapping('url', [new NotNullConstraint(), new NotBlankConstraint()]),
56
        ];
57
    }
58
}
59