| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; |
| 6 |
|
| 7 |
class ExcelError |
| 8 |
{ |
| 9 |
use ArrayEnabled; |
| 10 |
|
| 11 |
/** |
| 12 |
* List of error codes. |
| 13 |
* |
| 14 |
* @var array<string, string> |
| 15 |
*/ |
| 16 |
public const ERROR_CODES = [ |
| 17 |
'null' => '#NULL!', // 1 |
| 18 |
'divisionbyzero' => '#DIV/0!', // 2 |
| 19 |
'value' => '#VALUE!', // 3 |
| 20 |
'reference' => '#REF!', // 4 |
| 21 |
'name' => '#NAME?', // 5 |
| 22 |
'num' => '#NUM!', // 6 |
| 23 |
'na' => '#N/A', // 7 |
| 24 |
'gettingdata' => '#GETTING_DATA', // 8 |
| 25 |
'spill' => '#SPILL!', // 9 |
| 26 |
'connect' => '#CONNECT!', //10 |
| 27 |
'blocked' => '#BLOCKED!', //11 |
| 28 |
'unknown' => '#UNKNOWN!', //12 |
| 29 |
'field' => '#FIELD!', //13 |
| 30 |
'calculation' => '#CALC!', //14 |
| 31 |
]; |
| 32 |
|
| 33 |
/** |
| 34 |
* @param mixed $value |
| 35 |
*/ |
| 36 |
public static function throwError($value): string |
| 37 |
{ |
| 38 |
return in_array($value, self::ERROR_CODES, true) ? $value : self::ERROR_CODES['value']; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* ERROR_TYPE. |
| 43 |
* |
| 44 |
* @param mixed $value Value to check |
| 45 |
* |
| 46 |
* @return array<mixed>|int|string |
| 47 |
*/ |
| 48 |
public static function type($value = '') |
| 49 |
{ |
| 50 |
if (is_array($value)) { |
| 51 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); |
| 52 |
} |
| 53 |
|
| 54 |
$i = 1; |
| 55 |
foreach (self::ERROR_CODES as $errorCode) { |
| 56 |
if ($value === $errorCode) { |
| 57 |
return $i; |
| 58 |
} |
| 59 |
++$i; |
| 60 |
} |
| 61 |
|
| 62 |
return self::NA(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* NULL. |
| 67 |
* |
| 68 |
* Returns the error value #NULL! |
| 69 |
* |
| 70 |
* @return string #NULL! |
| 71 |
*/ |
| 72 |
public static function null(): string |
| 73 |
{ |
| 74 |
return self::ERROR_CODES['null']; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* NaN. |
| 79 |
* |
| 80 |
* Returns the error value #NUM! |
| 81 |
* |
| 82 |
* @return string #NUM! |
| 83 |
*/ |
| 84 |
public static function NAN(): string |
| 85 |
{ |
| 86 |
return self::ERROR_CODES['num']; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* REF. |
| 91 |
* |
| 92 |
* Returns the error value #REF! |
| 93 |
* |
| 94 |
* @return string #REF! |
| 95 |
*/ |
| 96 |
public static function REF(): string |
| 97 |
{ |
| 98 |
return self::ERROR_CODES['reference']; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* NA. |
| 103 |
* |
| 104 |
* Excel Function: |
| 105 |
* =NA() |
| 106 |
* |
| 107 |
* Returns the error value #N/A |
| 108 |
* #N/A is the error value that means "no value is available." |
| 109 |
* |
| 110 |
* @return string #N/A! |
| 111 |
*/ |
| 112 |
public static function NA(): string |
| 113 |
{ |
| 114 |
return self::ERROR_CODES['na']; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* VALUE. |
| 119 |
* |
| 120 |
* Returns the error value #VALUE! |
| 121 |
* |
| 122 |
* @return string #VALUE! |
| 123 |
*/ |
| 124 |
public static function VALUE(): string |
| 125 |
{ |
| 126 |
return self::ERROR_CODES['value']; |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* NAME. |
| 131 |
* |
| 132 |
* Returns the error value #NAME? |
| 133 |
* |
| 134 |
* @return string #NAME? |
| 135 |
*/ |
| 136 |
public static function NAME(): string |
| 137 |
{ |
| 138 |
return self::ERROR_CODES['name']; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* DIV0. |
| 143 |
* |
| 144 |
* @return string #DIV/0! |
| 145 |
*/ |
| 146 |
public static function DIV0(): string |
| 147 |
{ |
| 148 |
return self::ERROR_CODES['divisionbyzero']; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* CALC. |
| 153 |
* |
| 154 |
* @return string #CALC! |
| 155 |
*/ |
| 156 |
public static function CALC(): string |
| 157 |
{ |
| 158 |
return self::ERROR_CODES['calculation']; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* SPILL. |
| 163 |
* |
| 164 |
* @return string #SPILL! |
| 165 |
*/ |
| 166 |
public static function SPILL(): string |
| 167 |
{ |
| 168 |
return self::ERROR_CODES['spill']; |
| 169 |
} |
| 170 |
} |
| 171 |
|