ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FinancialValidations.php
Go to the documentation of this file.
1<?php
2
4
9
11{
15 public static function validateDate($date): float
16 {
18 }
19
23 public static function validateSettlementDate($settlement): float
24 {
25 return self::validateDate($settlement);
26 }
27
31 public static function validateMaturityDate($maturity): float
32 {
33 return self::validateDate($maturity);
34 }
35
39 public static function validateFloat($value): float
40 {
41 if (!is_numeric($value)) {
42 throw new Exception(Functions::VALUE());
43 }
44
45 return (float) $value;
46 }
47
51 public static function validateInt($value): int
52 {
53 if (!is_numeric($value)) {
54 throw new Exception(Functions::VALUE());
55 }
56
57 return (int) floor((float) $value);
58 }
59
63 public static function validateRate($rate): float
64 {
65 $rate = self::validateFloat($rate);
66 if ($rate < 0.0) {
67 throw new Exception(Functions::NAN());
68 }
69
70 return $rate;
71 }
72
76 public static function validateFrequency($frequency): int
77 {
78 $frequency = self::validateInt($frequency);
79 if (
80 ($frequency !== FinancialConstants::FREQUENCY_ANNUAL) &&
81 ($frequency !== FinancialConstants::FREQUENCY_SEMI_ANNUAL) &&
82 ($frequency !== FinancialConstants::FREQUENCY_QUARTERLY)
83 ) {
84 throw new Exception(Functions::NAN());
85 }
86
87 return $frequency;
88 }
89
93 public static function validateBasis($basis): int
94 {
95 if (!is_numeric($basis)) {
96 throw new Exception(Functions::VALUE());
97 }
98
99 $basis = (int) $basis;
100 if (($basis < 0) || ($basis > 4)) {
101 throw new Exception(Functions::NAN());
102 }
103
104 return $basis;
105 }
106
110 public static function validatePrice($price): float
111 {
112 $price = self::validateFloat($price);
113 if ($price < 0.0) {
114 throw new Exception(Functions::NAN());
115 }
116
117 return $price;
118 }
119
123 public static function validateParValue($parValue): float
124 {
125 $parValue = self::validateFloat($parValue);
126 if ($parValue < 0.0) {
127 throw new Exception(Functions::NAN());
128 }
129
130 return $parValue;
131 }
132
136 public static function validateYield($yield): float
137 {
138 $yield = self::validateFloat($yield);
139 if ($yield < 0.0) {
140 throw new Exception(Functions::NAN());
141 }
142
143 return $yield;
144 }
145
149 public static function validateDiscount($discount): float
150 {
151 $discount = self::validateFloat($discount);
152 if ($discount <= 0.0) {
153 throw new Exception(Functions::NAN());
154 }
155
156 return $discount;
157 }
158}
An exception for terminatinating execution or to throw for unit testing.
static getDateValue($dateValue, bool $allowBool=true)
getDateValue.
Definition: Helpers.php:31