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 / Engineering / ConvertBase.php

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

77 lines 1.8 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\Engineering;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
8 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
9 use TablePress\PhpOffice\PhpSpreadsheet\Shared\StringHelper;
10
11 abstract class ConvertBase
12 {
13 use ArrayEnabled;
14
15 /**
16 * @param mixed $value
17 */
18 protected static function validateValue($value): string
19 {
20 if (is_bool($value)) {
21 if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {
22 throw new Exception(ExcelError::VALUE());
23 }
24 $value = (int) $value;
25 }
26
27 if (is_numeric($value)) {
28 if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
29 $value = floor((float) $value);
30 }
31 }
32
33 return strtoupper(StringHelper::convertToString($value));
34 }
35
36 /**
37 * @param mixed $places
38 */
39 protected static function validatePlaces($places = null): ?int
40 {
41 if ($places === null) {
42 return $places;
43 }
44
45 if (is_numeric($places)) {
46 if ($places < 0 || $places > 10) {
47 throw new Exception(ExcelError::NAN());
48 }
49
50 return (int) $places;
51 }
52
53 throw new Exception(ExcelError::VALUE());
54 }
55
56 /**
57 * Formats a number base string value with leading zeroes.
58 *
59 * @param string $value The "number" to pad
60 * @param ?int $places The length that we want to pad this value
61 *
62 * @return string The padded "number"
63 */
64 protected static function nbrConversionFormat(string $value, ?int $places): string
65 {
66 if ($places !== null) {
67 if (strlen($value) <= $places) {
68 return substr(str_pad($value, $places, '0', STR_PAD_LEFT), -10);
69 }
70
71 return ExcelError::NAN();
72 }
73
74 return substr($value, -10);
75 }
76 }
77