ImmutableDateTime::applyOnChildBuilder()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bdf\Form\Attribute\Element\Date;
4
5
use Attribute;
6
use Bdf\Form\Attribute\AttributeForm;
7
use Bdf\Form\Attribute\ChildBuilderAttributeInterface;
8
use Bdf\Form\Attribute\Processor\CodeGenerator\AttributesProcessorGenerator;
9
use Bdf\Form\Child\ChildBuilderInterface;
10
11
/**
12
 * Use a DateTimeImmutable type as date time on the element
13
 *
14
 * Note: this attribute is not repeatable
15
 *
16
 * This attribute is equivalent to call :
17
 * <code>
18
 * $builder->dateTime('date')->immutable();
19
 * </code>
20
 *
21
 * Usage:
22
 * <code>
23
 * class MyForm extends AttributeForm
24
 * {
25
 *     #[ImmutableDateTime]
26
 *     private DateTimeElement $foo;
27
 * }
28
 * </code>
29
 *
30
 * @see \Bdf\Form\Leaf\Date\DateTimeElementBuilder::immutable() The called method
31
 * @see DateTimeClass For use a custom class name
32
 *
33
 * @implements ChildBuilderAttributeInterface<\Bdf\Form\Leaf\Date\DateTimeElementBuilder>
34
 */
35
#[Attribute(Attribute::TARGET_PROPERTY)]
36
final class ImmutableDateTime implements ChildBuilderAttributeInterface
37
{
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function applyOnChildBuilder(AttributeForm $form, ChildBuilderInterface $builder): void
42
    {
43 1
        $builder->immutable();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 2
    public function generateCodeForChildBuilder(string $name, AttributesProcessorGenerator $generator, AttributeForm $form): void
50
    {
51 2
        $generator->line('$?->immutable();', [$name]);
52
    }
53
}
54