Value::applyOnButtonBuilder()   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 0
Metric Value
cc 1
eloc 1
c 0
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\Button;
4
5
use Attribute;
6
use Bdf\Form\Attribute\AttributeForm;
7
use Bdf\Form\Attribute\Processor\CodeGenerator\AttributesProcessorGenerator;
8
use Bdf\Form\Attribute\Processor\GenerateConfiguratorStrategy;
9
use Bdf\Form\Button\ButtonBuilderInterface;
10
11
/**
12
 * Attribute for define the button value, used to check if the button is clicked
13
 *
14
 * Note: this attribute is not repeatable
15
 *
16
 * This attribute is equivalent to call :
17
 * <code>
18
 * $builder->button('btn')->value('Foo');
19
 * </code>
20
 *
21
 * Usage:
22
 * <code>
23
 * class MyForm extends AttributeForm
24
 * {
25
 *     #[Value('Foo')]
26
 *     private ButtonInterface $btn;
27
 * }
28
 * </code>
29
 *
30
 * @see ButtonBuilderInterface::value() The called method
31
 */
32
#[Attribute(Attribute::TARGET_PROPERTY)]
33
final class Value implements ButtonBuilderAttributeInterface
34
{
35 4
    public function __construct(
36
        /**
37
         * The button HTTP value
38
         * @readonly
39
         */
40
        private string $value,
41
    ) {
42 4
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function applyOnButtonBuilder(AttributeForm $form, ButtonBuilderInterface $builder): void
48
    {
49 1
        $builder->value($this->value);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 3
    public function generateCodeForButtonBuilder(AttributesProcessorGenerator $generator, AttributeForm $form): void
56
    {
57 3
        $generator->line('    ->value(?)', [$this->value]);
58
    }
59
}
60