Value   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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