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.

Differences Between: [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

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