Passed
Push — develop ( 00d2f1...1275e7 )
by Daniel
05:07
created

Form::setLastModified()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Component\Form;
4
5
use ApiPlatform\Core\Annotation\ApiProperty;
6
use ApiPlatform\Core\Annotation\ApiResource;
7
use Doctrine\ORM\Mapping as ORM;
8
use Silverback\ApiComponentBundle\Entity\Component\AbstractComponent;
9
use Silverback\ApiComponentBundle\Validator\Constraints as ACBAssert;
10
use Symfony\Component\Serializer\Annotation\Groups;
11
use Symfony\Component\Validator\Constraints as Assert;
12
use Symfony\Component\Validator\Mapping\ClassMetadata;
13
14
/**
15
 * Class Form
16
 * @package Silverback\ApiComponentBundle\Entity\Component\Form
17
 * @author Daniel West <[email protected]>
18
 * @ApiResource(
19
 *     collectionOperations={
20
 *         "get"={"method"="GET"},
21
 *         "post"={"method"="POST"},
22
 *     },
23
 *     itemOperations={
24
 *         "get"={"method"="GET"},
25
 *         "delete"={"method"="DELETE"},
26
 *         "put"={"method"="PUT"},
27
 *         "validate_item"={"method"="PATCH", "route_name"="silverback_api_component_form_validate_item", "denormalization_context"={"groups"={"none"}}},
28
 *         "validate_form"={"method"="POST", "route_name"="silverback_api_component_form_submit", "denormalization_context"={"groups"={"none"}}}
29
 *     },
30
 *     shortName="component/form"
31
 * )
32
 * @ORM\Entity()
33
 */
34
class Form extends AbstractComponent
35
{
36
    /**
37
     * @ORM\Column()
38
     * @Groups({"component_write"})
39
     * @var string
40
     */
41
    private $formType;
42
43
    /**
44
     * @ORM\Column()
45
     * @Groups({"component_write"})
46
     * @var null|string
47
     */
48
    private $successHandler;
49
50
    /**
51
     * @ApiProperty(writable=false)
52
     * @var null|\DateTime
53
     */
54
    private $lastModified;
55
56
    /**
57
     * @var null|FormView
58
     */
59
    private $form;
60
61 2
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
62
    {
63 2
        $metadata->addPropertyConstraints(
64 2
            'formType',
65
            [
66 2
                new ACBAssert\FormTypeClass(),
67 2
                new Assert\NotBlank()
68
            ]
69
        );
70 2
        $metadata->addPropertyConstraint(
71 2
            'successHandler',
72 2
            new ACBAssert\FormHandlerClass()
73
        );
74 2
    }
75
76
    /**
77
     * @return string
78
     */
79 2
    public function getFormType(): string
80
    {
81 2
        return $this->formType;
82
    }
83
84
    /**
85
     * @param string $formType
86
     */
87 2
    public function setFormType(string $formType): void
88
    {
89 2
        $this->formType = $formType;
90 2
    }
91
92
    /**
93
     * @return null|string
94
     */
95 1
    public function getSuccessHandler(): ?string
96
    {
97 1
        return $this->successHandler;
98
    }
99
100
    /**
101
     * @param null|string $successHandler
102
     */
103 2
    public function setSuccessHandler(?string $successHandler): void
104
    {
105 2
        $this->successHandler = $successHandler;
106 2
    }
107
108
    /**
109
     * @return null|FormView
110
     */
111
    public function getForm(): ?FormView
112
    {
113
        return $this->form;
114
    }
115
116
    /**
117
     * @param null|FormView $form
118
     */
119
    public function setForm(?FormView $form): void
120
    {
121
        $this->form = $form;
122
    }
123
124
    /**
125
     * @return \DateTime|null
126
     */
127 1
    public function getLastModified(): ?\DateTime
128
    {
129 1
        return $this->lastModified;
130
    }
131
132
    /**
133
     * @param \DateTime|null $lastModified
134
     */
135 1
    public function setLastModified(?\DateTime $lastModified): void
136
    {
137 1
        $this->lastModified = $lastModified;
138 1
    }
139
}
140