Timezone::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
 * Define the time used for parse and convert the date
13
 *
14
 * Note: this attribute is not repeatable
15
 *
16
 * This attribute is equivalent to call :
17
 * <code>
18
 * $builder->dateTime('date')->timezone('Europe/Paris');
19
 * </code>
20
 *
21
 * Usage:
22
 * <code>
23
 * class MyForm extends AttributeForm
24
 * {
25
 *     #[Timezone('Europe/Paris')]
26
 *     private DateTimeElement $foo;
27
 * }
28
 * </code>
29
 *
30
 * @see \Bdf\Form\Leaf\Date\DateTimeElementBuilder::timezone() The called method
31
 *
32
 * @implements ChildBuilderAttributeInterface<\Bdf\Form\Leaf\Date\DateTimeElementBuilder>
33
 */
34
#[Attribute(Attribute::TARGET_PROPERTY)]
35
final class Timezone implements ChildBuilderAttributeInterface
36
{
37 3
    public function __construct(
38
        /**
39
         * The timezone name or offset
40
         *
41
         * @var non-empty-string
42
         * @readonly
43
         */
44
        private string $timezone,
45
    ) {
46 3
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function applyOnChildBuilder(AttributeForm $form, ChildBuilderInterface $builder): void
52
    {
53 1
        $builder->timezone($this->timezone);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2
    public function generateCodeForChildBuilder(string $name, AttributesProcessorGenerator $generator, AttributeForm $form): void
60
    {
61 2
        $generator->line('$?->timezone(?);', [$name, $this->timezone]);
62
    }
63
}
64