Timezone   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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