Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\Information;
   4  
   5  use 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       * List of error codes. Replaced by constant;
  35       * previously it was public and updateable, allowing
  36       * user to make inappropriate alterations.
  37       *
  38       * @deprecated 1.25.0 Use ERROR_CODES constant instead.
  39       *
  40       * @var array<string, string>
  41       */
  42      public static $errorCodes = self::ERROR_CODES;
  43  
  44      /**
  45       * @param mixed $value
  46       */
  47      public static function throwError($value): string
  48      {
  49          return in_array($value, self::ERROR_CODES, true) ? $value : self::ERROR_CODES['value'];
  50      }
  51  
  52      /**
  53       * ERROR_TYPE.
  54       *
  55       * @param mixed $value Value to check
  56       *
  57       * @return array|int|string
  58       */
  59      public static function type($value = '')
  60      {
  61          if (is_array($value)) {
  62              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
  63          }
  64  
  65          $i = 1;
  66          foreach (self::ERROR_CODES as $errorCode) {
  67              if ($value === $errorCode) {
  68                  return $i;
  69              }
  70              ++$i;
  71          }
  72  
  73          return self::NA();
  74      }
  75  
  76      /**
  77       * NULL.
  78       *
  79       * Returns the error value #NULL!
  80       *
  81       * @return string #NULL!
  82       */
  83      public static function null(): string
  84      {
  85          return self::ERROR_CODES['null'];
  86      }
  87  
  88      /**
  89       * NaN.
  90       *
  91       * Returns the error value #NUM!
  92       *
  93       * @return string #NUM!
  94       */
  95      public static function NAN(): string
  96      {
  97          return self::ERROR_CODES['num'];
  98      }
  99  
 100      /**
 101       * REF.
 102       *
 103       * Returns the error value #REF!
 104       *
 105       * @return string #REF!
 106       */
 107      public static function REF(): string
 108      {
 109          return self::ERROR_CODES['reference'];
 110      }
 111  
 112      /**
 113       * NA.
 114       *
 115       * Excel Function:
 116       *        =NA()
 117       *
 118       * Returns the error value #N/A
 119       *        #N/A is the error value that means "no value is available."
 120       *
 121       * @return string #N/A!
 122       */
 123      public static function NA(): string
 124      {
 125          return self::ERROR_CODES['na'];
 126      }
 127  
 128      /**
 129       * VALUE.
 130       *
 131       * Returns the error value #VALUE!
 132       *
 133       * @return string #VALUE!
 134       */
 135      public static function VALUE(): string
 136      {
 137          return self::ERROR_CODES['value'];
 138      }
 139  
 140      /**
 141       * NAME.
 142       *
 143       * Returns the error value #NAME?
 144       *
 145       * @return string #NAME?
 146       */
 147      public static function NAME(): string
 148      {
 149          return self::ERROR_CODES['name'];
 150      }
 151  
 152      /**
 153       * DIV0.
 154       *
 155       * @return string #DIV/0!
 156       */
 157      public static function DIV0(): string
 158      {
 159          return self::ERROR_CODES['divisionbyzero'];
 160      }
 161  
 162      /**
 163       * CALC.
 164       *
 165       * @return string #CALC!
 166       */
 167      public static function CALC(): string
 168      {
 169          return self::ERROR_CODES['calculation'];
 170      }
 171  }