ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FloatTransformation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
30 {
33  use ProblemBuilder;
34 
38  public function transform($from): float
39  {
40  $this->check($from);
41  return (float) $from;
42  }
43 
47  public function getError(): string
48  {
49  return 'The value MUST be of type string.';
50  }
51 
55  public function check($value)
56  {
57  if (!$this->accepts($value)) {
58  throw new UnexpectedValueException($this->getErrorMessage($value));
59  }
60 
61  return null;
62  }
63 
67  public function accepts($value): bool
68  {
69  return is_float($value);
70  }
71 
75  public function problemWith($value): ?string
76  {
77  if (!$this->accepts($value)) {
78  return $this->getErrorMessage($value);
79  }
80 
81  return null;
82  }
83 }
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getErrorMessage($value)