PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / Financial / FinancialValidations.php

FinancialValidations.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Financial/FinancialValidations.php

159 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
8 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
9
10 class FinancialValidations
11 {
12 /**
13 * @param mixed $date
14 */
15 public static function validateDate($date): float
16 {
17 return DateTimeExcel\Helpers::getDateValue($date);
18 }
19
20 /**
21 * @param mixed $settlement
22 */
23 public static function validateSettlementDate($settlement): float
24 {
25 return self::validateDate($settlement);
26 }
27
28 /**
29 * @param mixed $maturity
30 */
31 public static function validateMaturityDate($maturity): float
32 {
33 return self::validateDate($maturity);
34 }
35
36 /**
37 * @param mixed $value
38 */
39 public static function validateFloat($value): float
40 {
41 if (!is_numeric($value)) {
42 throw new Exception(ExcelError::VALUE());
43 }
44
45 return (float) $value;
46 }
47
48 /**
49 * @param mixed $value
50 */
51 public static function validateInt($value): int
52 {
53 if (!is_numeric($value)) {
54 throw new Exception(ExcelError::VALUE());
55 }
56
57 return (int) floor((float) $value);
58 }
59
60 /**
61 * @param mixed $rate
62 */
63 public static function validateRate($rate): float
64 {
65 $rate = self::validateFloat($rate);
66 if ($rate < 0.0) {
67 throw new Exception(ExcelError::NAN());
68 }
69
70 return $rate;
71 }
72
73 /**
74 * @param mixed $frequency
75 */
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(ExcelError::NAN());
85 }
86
87 return $frequency;
88 }
89
90 /**
91 * @param mixed $basis
92 */
93 public static function validateBasis($basis): int
94 {
95 if (!is_numeric($basis)) {
96 throw new Exception(ExcelError::VALUE());
97 }
98
99 $basis = (int) $basis;
100 if (($basis < 0) || ($basis > 4)) {
101 throw new Exception(ExcelError::NAN());
102 }
103
104 return $basis;
105 }
106
107 /**
108 * @param mixed $price
109 */
110 public static function validatePrice($price): float
111 {
112 $price = self::validateFloat($price);
113 if ($price < 0.0) {
114 throw new Exception(ExcelError::NAN());
115 }
116
117 return $price;
118 }
119
120 /**
121 * @param mixed $parValue
122 */
123 public static function validateParValue($parValue): float
124 {
125 $parValue = self::validateFloat($parValue);
126 if ($parValue < 0.0) {
127 throw new Exception(ExcelError::NAN());
128 }
129
130 return $parValue;
131 }
132
133 /**
134 * @param mixed $yield
135 */
136 public static function validateYield($yield): float
137 {
138 $yield = self::validateFloat($yield);
139 if ($yield < 0.0) {
140 throw new Exception(ExcelError::NAN());
141 }
142
143 return $yield;
144 }
145
146 /**
147 * @param mixed $discount
148 */
149 public static function validateDiscount($discount): float
150 {
151 $discount = self::validateFloat($discount);
152 if ($discount <= 0.0) {
153 throw new Exception(ExcelError::NAN());
154 }
155
156 return $discount;
157 }
158 }
159