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

DocumentMapping   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClass() 0 4 1
A getConstraints() 0 4 1
A getPropertyMappings() 0 7 1
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