ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ConvertBase.php
Go to the documentation of this file.
1<?php
2
4
7
9{
10 protected static function validateValue($value): string
11 {
12 if (is_bool($value)) {
14 throw new Exception(Functions::VALUE());
15 }
16 $value = (int) $value;
17 }
18
19 if (is_numeric($value)) {
21 $value = floor((float) $value);
22 }
23 }
24
25 return strtoupper((string) $value);
26 }
27
28 protected static function validatePlaces($places = null): ?int
29 {
30 if ($places === null) {
31 return $places;
32 }
33
34 if (is_numeric($places)) {
35 if ($places < 0 || $places > 10) {
36 throw new Exception(Functions::NAN());
37 }
38
39 return (int) $places;
40 }
41
42 throw new Exception(Functions::VALUE());
43 }
44
53 protected static function nbrConversionFormat(string $value, ?int $places): string
54 {
55 if ($places !== null) {
56 if (strlen($value) <= $places) {
57 return substr(str_pad($value, $places, '0', STR_PAD_LEFT), -10);
58 }
59
60 return Functions::NAN();
61 }
62
63 return substr($value, -10);
64 }
65}
An exception for terminatinating execution or to throw for unit testing.
static nbrConversionFormat(string $value, ?int $places)
Formats a number base string value with leading zeroes.
Definition: ConvertBase.php:53
static getCompatibilityMode()
Return the current Compatibility Mode.
Definition: Functions.php:93