• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

keradus / PHP-CS-Fixer / 22042339290

15 Feb 2026 08:14PM UTC coverage: 92.957% (-0.2%) from 93.171%
22042339290

push

github

keradus
test: check PHP env in CI jobs

29302 of 31522 relevant lines covered (92.96%)

44.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/src/Future.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer;
16

17
/**
18
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
19
 *
20
 * @internal
21
 *
22
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
23
 */
24
final class Future
25
{
26
    private static bool $isFutureModeEnforced = false;
27

28
    /**
29
     * @var array<string, true>
30
     */
31
    private static array $deprecations = [];
32

33
    private function __construct()
34
    {
35
        // cannot create instance
36
    }
×
37

38
    /**
39
     * @return mixed
40
     */
41
    public static function runWithEnforcedFutureMode(callable $callback)
42
    {
43
        try {
44
            self::$isFutureModeEnforced = true;
×
45

46
            return $callback();
×
47
        } finally {
48
            self::$isFutureModeEnforced = false;
×
49
        }
50
    }
51

52
    public static function isFutureModeEnabled(): bool
53
    {
54
        return self::$isFutureModeEnforced || filter_var(
4✔
55
            getenv('PHP_CS_FIXER_FUTURE_MODE'),
4✔
56
            \FILTER_VALIDATE_BOOL,
4✔
57
        );
4✔
58
    }
59

60
    public static function triggerDeprecation(\Exception $futureException): void
61
    {
62
        if (self::isFutureModeEnabled()) {
2✔
63
            throw new \RuntimeException(
1✔
64
                'Your are using something deprecated, see previous exception. Aborting execution because `PHP_CS_FIXER_FUTURE_MODE` environment variable is set.',
1✔
65
                0,
1✔
66
                $futureException,
1✔
67
            );
1✔
68
        }
69

70
        $message = $futureException->getMessage();
1✔
71

72
        self::$deprecations[$message] = true;
1✔
73
        @trigger_error($message, \E_USER_DEPRECATED);
1✔
74
    }
75

76
    /**
77
     * @return list<string>
78
     */
79
    public static function getTriggeredDeprecations(): array
80
    {
81
        $triggeredDeprecations = array_keys(self::$deprecations);
2✔
82
        sort($triggeredDeprecations);
2✔
83

84
        return $triggeredDeprecations;
2✔
85
    }
86

87
    /**
88
     * @template T
89
     *
90
     * @param T $new
91
     * @param T $old
92
     *
93
     * @return T
94
     *
95
     * @TODO v4.0: remove this method, ensure code compiles, create getV5OrV4. While removing, ensure to document in `UPGRADE-vX.md` file.
96
     */
97
    public static function getV4OrV3($new, $old)
98
    {
99
        return self::getNewOrOld($new, $old);
2✔
100
    }
101

102
    /**
103
     * @template T
104
     *
105
     * @param T $new
106
     * @param T $old
107
     *
108
     * @return T
109
     */
110
    private static function getNewOrOld($new, $old)
111
    {
112
        return self::isFutureModeEnabled() ? $new : $old;
2✔
113
    }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc