Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401]

   1  <?php
   2  
   3  namespace Box\Spout\Common\Helper;
   4  
   5  /**
   6   * Class CellTypeHelper
   7   * This class provides helper functions to determine the type of the cell value
   8   */
   9  class CellTypeHelper
  10  {
  11      /**
  12       * @param $value
  13       * @return bool Whether the given value is considered "empty"
  14       */
  15      public static function isEmpty($value)
  16      {
  17          return ($value === null || $value === '');
  18      }
  19  
  20      /**
  21       * @param $value
  22       * @return bool Whether the given value is a non empty string
  23       */
  24      public static function isNonEmptyString($value)
  25      {
  26          return (gettype($value) === 'string' && $value !== '');
  27      }
  28  
  29      /**
  30       * Returns whether the given value is numeric.
  31       * A numeric value is from type "integer" or "double" ("float" is not returned by gettype).
  32       *
  33       * @param $value
  34       * @return bool Whether the given value is numeric
  35       */
  36      public static function isNumeric($value)
  37      {
  38          $valueType = gettype($value);
  39  
  40          return ($valueType === 'integer' || $valueType === 'double');
  41      }
  42  
  43      /**
  44       * Returns whether the given value is boolean.
  45       * "true"/"false" and 0/1 are not booleans.
  46       *
  47       * @param $value
  48       * @return bool Whether the given value is boolean
  49       */
  50      public static function isBoolean($value)
  51      {
  52          return gettype($value) === 'boolean';
  53      }
  54  
  55      /**
  56       * Returns whether the given value is a DateTime or DateInterval object.
  57       *
  58       * @param $value
  59       * @return bool Whether the given value is a DateTime or DateInterval object
  60       */
  61      public static function isDateTimeOrDateInterval($value)
  62      {
  63          return (
  64              $value instanceof \DateTime ||
  65              $value instanceof \DateInterval
  66          );
  67      }
  68  }