Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  
   3  /**
   4   * SCSSPHP
   5   *
   6   * @copyright 2012-2020 Leaf Corcoran
   7   *
   8   * @license http://opensource.org/licenses/MIT MIT
   9   *
  10   * @link http://scssphp.github.io/scssphp
  11   */
  12  
  13  namespace ScssPhp\ScssPhp;
  14  
  15  final class Warn
  16  {
  17      /**
  18       * @var callable|null
  19       * @phpstan-var (callable(string, bool): void)|null
  20       */
  21      private static $callback;
  22  
  23      /**
  24       * Prints a warning message associated with the current `@import` or function call.
  25       *
  26       * This may only be called within a custom function or importer callback.
  27       *
  28       * @param string $message
  29       *
  30       * @return void
  31       */
  32      public static function warning($message)
  33      {
  34          self::reportWarning($message, false);
  35      }
  36  
  37      /**
  38       * Prints a deprecation warning message associated with the current `@import` or function call.
  39       *
  40       * This may only be called within a custom function or importer callback.
  41       *
  42       * @param string $message
  43       *
  44       * @return void
  45       */
  46      public static function deprecation($message)
  47      {
  48          self::reportWarning($message, true);
  49      }
  50  
  51      /**
  52       * @param callable|null $callback
  53       *
  54       * @return callable|null The previous warn callback
  55       *
  56       * @phpstan-param (callable(string, bool): void)|null $callback
  57       *
  58       * @phpstan-return (callable(string, bool): void)|null
  59       *
  60       * @internal
  61       */
  62      public static function setCallback(callable $callback = null)
  63      {
  64          $previousCallback = self::$callback;
  65          self::$callback = $callback;
  66  
  67          return $previousCallback;
  68      }
  69  
  70      /**
  71       * @param string $message
  72       * @param bool   $deprecation
  73       *
  74       * @return void
  75       */
  76      private static function reportWarning($message, $deprecation)
  77      {
  78          if (self::$callback === null) {
  79              throw new \BadMethodCallException('The warning Reporter may only be called within a custom function or importer callback.');
  80          }
  81  
  82          \call_user_func(self::$callback, $message, $deprecation);
  83      }
  84  }