Issues (116)

src/Button/SubmitButtonBuilder.php (2 issues)

1
<?php
2
3
namespace Bdf\Form\Button;
4
5
use Bdf\Form\Aggregate\FormBuilderInterface;
6
7
/**
8
 * Builder for a submit button
9
 *
10
 * <code>
11
 * $builder
12
 *     ->submit('btn')
13
 *     ->value('create')
14
 *     ->groups(['creation'])
15
 * ;
16
 * </code>
17
 *
18
 * @see SubmitButton
19
 * @see FormBuilderInterface::submit()
20
 */
21
final class SubmitButtonBuilder implements ButtonBuilderInterface
22
{
23
    /**
24
     * @var string
25
     */
26
    private $name;
27
28
    /**
29
     * @var class-string<ButtonInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<ButtonInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<ButtonInterface>.
Loading history...
30
     */
31
    private $buttonClass;
32
33
    /**
34
     * @var string
35
     */
36
    private $value = 'ok';
37
38
    /**
39
     * @var array
40
     */
41
    private $groups = [];
42
43
44
    /**
45
     * SubmitButtonBuilder constructor.
46
     *
47
     * @param string $name
48
     * @param class-string<ButtonInterface> $buttonClass
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<ButtonInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<ButtonInterface>.
Loading history...
49
     */
50 8
    public function __construct(string $name, string $buttonClass = SubmitButton::class)
51
    {
52 8
        $this->name = $name;
53 8
        $this->buttonClass = $buttonClass;
54 8
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 1
    public function value(string $value): ButtonBuilderInterface
60
    {
61 1
        $this->value = $value;
62
63 1
        return $this;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 1
    public function groups(array $groups): ButtonBuilderInterface
70
    {
71 1
        $this->groups = $groups;
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 8
    public function buildButton(): ButtonInterface
80
    {
81 8
        return new $this->buttonClass($this->name, $this->value, $this->groups);
82
    }
83
}
84