b2pweb /
bdf-form
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Bdf\Form\Leaf; |
||||
| 4 | |||||
| 5 | use Bdf\Form\Aggregate\FormBuilderInterface; |
||||
| 6 | use Bdf\Form\ElementInterface; |
||||
| 7 | use Bdf\Form\Leaf\Transformer\LocalizedIntegerTransformer; |
||||
| 8 | use Bdf\Form\Transformer\TransformerInterface; |
||||
| 9 | use Bdf\Form\Validator\ValueValidatorInterface; |
||||
| 10 | use NumberFormatter; |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * Builder for an integer element |
||||
| 14 | * |
||||
| 15 | * <code> |
||||
| 16 | * $builder->integer('id') |
||||
| 17 | * ->required() |
||||
| 18 | * ->min(15) |
||||
| 19 | * ->raw() |
||||
| 20 | * ; |
||||
| 21 | * </code> |
||||
| 22 | * |
||||
| 23 | * @see IntegerElement |
||||
| 24 | * @see FormBuilderInterface::integer() |
||||
| 25 | * |
||||
| 26 | * @extends NumberElementBuilder<IntegerElement> |
||||
| 27 | */ |
||||
| 28 | class IntegerElementBuilder extends NumberElementBuilder |
||||
| 29 | { |
||||
| 30 | /** |
||||
| 31 | * @var bool |
||||
| 32 | */ |
||||
| 33 | private $grouping = false; |
||||
| 34 | |||||
| 35 | /** |
||||
| 36 | * @var NumberFormatter::ROUND_* |
||||
| 37 | */ |
||||
| 38 | private $roundingMode = NumberFormatter::ROUND_DOWN; |
||||
| 39 | |||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * Enable grouping of thousands |
||||
| 43 | * |
||||
| 44 | * Note: The element must not in raw() mode to works |
||||
| 45 | * |
||||
| 46 | * @param bool $flag Enable or disable grouping |
||||
| 47 | * |
||||
| 48 | * @return $this |
||||
| 49 | */ |
||||
| 50 | 1 | public function grouping(bool $flag = true): self |
|||
| 51 | { |
||||
| 52 | 1 | $this->grouping = $flag; |
|||
| 53 | |||||
| 54 | 1 | return $this; |
|||
| 55 | } |
||||
| 56 | |||||
| 57 | /** |
||||
| 58 | * How to round the decimal values |
||||
| 59 | * |
||||
| 60 | * Note: The element must not in raw() mode to works |
||||
| 61 | * |
||||
| 62 | * @param NumberFormatter::ROUND_* $mode One of the IntegerToLocalizedStringTransformer::ROUND_ constant |
||||
| 63 | * |
||||
| 64 | * @return $this |
||||
| 65 | */ |
||||
| 66 | 1 | public function roundingMode(int $mode): self |
|||
| 67 | { |
||||
| 68 | 1 | $this->roundingMode = $mode; |
|||
|
0 ignored issues
–
show
|
|||||
| 69 | |||||
| 70 | 1 | return $this; |
|||
| 71 | } |
||||
| 72 | |||||
| 73 | /** |
||||
| 74 | * {@inheritdoc} |
||||
| 75 | */ |
||||
| 76 | 106 | protected function createElement(ValueValidatorInterface $validator, TransformerInterface $transformer): ElementInterface |
|||
| 77 | { |
||||
| 78 | 106 | return new IntegerElement($validator, $transformer, $this->getChoices()); |
|||
| 79 | } |
||||
| 80 | |||||
| 81 | /** |
||||
| 82 | * {@inheritdoc} |
||||
| 83 | */ |
||||
| 84 | 88 | protected function numberTransformer(): TransformerInterface |
|||
| 85 | { |
||||
| 86 | 88 | return new LocalizedIntegerTransformer($this->grouping, $this->roundingMode); |
|||
|
0 ignored issues
–
show
$this->roundingMode of type NumberFormatter is incompatible with the type integer expected by parameter $roundingMode of Bdf\Form\Leaf\Transforme...nsformer::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 87 | } |
||||
| 88 | } |
||||
| 89 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..