ImmutableDateTime   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyOnChildBuilder() 0 3 1
A generateCodeForChildBuilder() 0 3 1
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