Passed
Push — develop ( 53a66f...07e04a )
by Daniel
05:35
created

FeatureColumns   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setTitle() 0 3 1
A loadValidatorMetadata() 0 8 1
A getTitle() 0 3 1
A getColumns() 0 3 1
A setColumns() 0 3 1
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Component\Feature\Columns;
4
5
use ApiPlatform\Core\Annotation\ApiResource;
6
use Doctrine\ORM\Mapping as ORM;
7
use Silverback\ApiComponentBundle\Entity\Component\Feature\AbstractFeature;
8
use Symfony\Component\Serializer\Annotation\Groups;
9
use Symfony\Component\Validator\Constraints as Assert;
10
use Symfony\Component\Validator\Mapping\ClassMetadata;
11
12
/**
13
 * Class FeatureColumns
14
 * @package Silverback\ApiComponentBundle\Entity\Component\FeatureHorizontal
15
 * @author Daniel West <[email protected]>
16
 * @ApiResource(shortName="component/feature_columns")
17
 * @ORM\Entity()
18
 */
19
class FeatureColumns extends AbstractFeature
20
{
21
    /**
22
     * @Groups({"component", "content"})
23
     * @var int
24
     */
25
    protected $columns = 3;
26
27
    /**
28
     * @Groups({"component", "content"})
29
     * @var null|string
30
     */
31
    protected $title;
32
33
    /**
34
     * @param ClassMetadata $metadata
35
     */
36 1
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
37
    {
38 1
        $metadata->addPropertyConstraint(
39 1
            'columns',
40 1
            new Assert\Range(
41
                [
42 1
                    'min' => 1,
43
                    'minMessage' => 'The FeatureColumns component must have at least 1 column'
44
                ]
45
            )
46
        );
47 1
    }
48
49
    /**
50
     * @return int
51
     */
52 1
    public function getColumns(): int
53
    {
54 1
        return $this->columns;
55
    }
56
57
    /**
58
     * @param int $columns
59
     */
60 1
    public function setColumns(int $columns): void
61
    {
62 1
        $this->columns = $columns;
63 1
    }
64
65
    /**
66
     * @return null|string
67
     */
68 1
    public function getTitle(): ?string
69
    {
70 1
        return $this->title;
71
    }
72
73
    /**
74
     * @param null|string $title
75
     */
76 1
    public function setTitle(?string $title): void
77
    {
78 1
        $this->title = $title;
79 1
    }
80
}
81