aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/scssphp/scssphp/src/Warn.php
blob: 592b44c70782e9a971a108156c4f998f9572d104 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php

/**
 * SCSSPHP
 *
 * @copyright 2012-2020 Leaf Corcoran
 *
 * @license http://opensource.org/licenses/MIT MIT
 *
 * @link http://scssphp.github.io/scssphp
 */

namespace ScssPhp\ScssPhp;

final class Warn
{
    /**
     * @var callable|null
     * @phpstan-var (callable(string, bool): void)|null
     */
    private static $callback;

    /**
     * Prints a warning message associated with the current `@import` or function call.
     *
     * This may only be called within a custom function or importer callback.
     *
     * @param string $message
     *
     * @return void
     */
    public static function warning($message)
    {
        self::reportWarning($message, false);
    }

    /**
     * Prints a deprecation warning message associated with the current `@import` or function call.
     *
     * This may only be called within a custom function or importer callback.
     *
     * @param string $message
     *
     * @return void
     */
    public static function deprecation($message)
    {
        self::reportWarning($message, true);
    }

    /**
     * @param callable|null $callback
     *
     * @return callable|null The previous warn callback
     *
     * @phpstan-param (callable(string, bool): void)|null $callback
     *
     * @phpstan-return (callable(string, bool): void)|null
     *
     * @internal
     */
    public static function setCallback(callable $callback = null)
    {
        $previousCallback = self::$callback;
        self::$callback = $callback;

        return $previousCallback;
    }

    /**
     * @param string $message
     * @param bool   $deprecation
     *
     * @return void
     */
    private static function reportWarning($message, $deprecation)
    {
        if (self::$callback === null) {
            throw new \BadMethodCallException('The warning Reporter may only be called within a custom function or importer callback.');
        }

        \call_user_func(self::$callback, $message, $deprecation);
    }
}