generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHasStep.php
35 lines (29 loc) · 953 Bytes
/
HasStep.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Attribute\FormControl\Input;
use function is_numeric;
/**
* Is used by widgets that implement the step method.
*/
trait HasStep
{
/**
* Set the step attribute valid for date, month, week, time, datetime-local, number, and range, the step attribute
* is a number that specifies the granularity that the value must adhere to.
*
* @param int|string $value The value granularity of the element’s value.
*
* @throws \InvalidArgumentException If the value is not numeric.
*
* @return static A new instance of the current class with the specified step value.
*/
public function step(int|string $value): static
{
if (!is_numeric($value)) {
throw new \InvalidArgumentException('The value must be a number.');
}
$new = clone $this;
$new->attributes['step'] = $value;
return $new;
}
}