Raw::generateCodeForChildBuilder()   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 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bdf\Form\Attribute\Element;
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
use Bdf\Form\Leaf\NumberElementBuilder;
11
12
/**
13
 * Change the raw number mode
14
 *
15
 * In row mode, the number is parsed using a cast instead of use localized number parser
16
 *
17
 * This attribute is equivalent to call :
18
 * <code>
19
 * $builder->float('foo')->raw();
20
 * </code>
21
 *
22
 * Usage:
23
 * <code>
24
 * class MyForm extends AttributeForm
25
 * {
26
 *     #[Raw]
27
 *     private IntegerElement $foo;
28
 * }
29
 * </code>
30
 *
31
 * @see NumberElementBuilder::raw() The called method
32
 *
33
 * @implements ChildBuilderAttributeInterface<\Bdf\Form\Leaf\NumberElementBuilder>
34
 */
35
#[Attribute(Attribute::TARGET_PROPERTY)]
36
final class Raw implements ChildBuilderAttributeInterface
37
{
38 3
    public function __construct(
39
        /**
40
         * Enable or disable raw mode for parsing numbers
41
         *
42
         * @readonly
43
         */
44
        private bool $flag = true,
45
    ) {
46 3
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function applyOnChildBuilder(AttributeForm $form, ChildBuilderInterface $builder): void
52
    {
53 1
        $builder->raw($this->flag);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2
    public function generateCodeForChildBuilder(string $name, AttributesProcessorGenerator $generator, AttributeForm $form): void
60
    {
61 2
        $generator->line('$?->raw(?);', [$name, $this->flag]);
62
    }
63
}
64