1 | <?php |
||
14 | class PointNumber implements ValidateRuleInterface |
||
15 | { |
||
16 | /** |
||
17 | * Represents the precision of the float. |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $precision; |
||
22 | |||
23 | /** |
||
24 | * Represents the scale for the float which determines the range of accepted values. |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $scale; |
||
29 | |||
30 | /** |
||
31 | * @param int $precision |
||
32 | * @param int $scale |
||
33 | */ |
||
34 | 12 | public function __construct(int $precision = 10, int $scale = 0) |
|
39 | |||
40 | /** |
||
41 | * Check that the value in the given field is a valid fixed point with the appropriate precision and scale. |
||
42 | * |
||
43 | * @param object $subject |
||
44 | * @param string $field |
||
45 | * |
||
46 | * @return bool |
||
47 | */ |
||
48 | 12 | public function __invoke($subject, string $field): bool |
|
63 | |||
64 | /** |
||
65 | * Ensures the correct precision. |
||
66 | * |
||
67 | * @param int $numBeforeDecimal |
||
68 | * @param int $numAfterDecimal |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 6 | protected function checkPrecision(int $numBeforeDecimal, int $numAfterDecimal) |
|
76 | |||
77 | /** |
||
78 | * Ensures the correct scale. |
||
79 | * |
||
80 | * @param int $numAfterDecimal |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | 6 | protected function checkScale(int $numAfterDecimal) |
|
88 | } |
||
89 |