Raw   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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