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

PHP-CS-Fixer / PHP-CS-Fixer / 21112018201

18 Jan 2026 12:50PM UTC coverage: 92.982% (-0.03%) from 93.007%
21112018201

push

github

web-flow
docs: show default value for future mode (#9355)

15 of 21 new or added lines in 2 files covered. (71.43%)

3 existing lines in 1 file now uncovered.

29175 of 31377 relevant lines covered (92.98%)

44.12 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
    public static function runWithEnforcedFutureMode(callable $callback): void
39
    {
40
        try {
NEW
41
            self::$isFutureModeEnforced = true;
×
NEW
42
            $callback();
×
43
        } finally {
NEW
44
            self::$isFutureModeEnforced = false;
×
45
        }
46
    }
47

48
    public static function isFutureModeEnabled(): bool
49
    {
50
        return self::$isFutureModeEnforced || filter_var(
4✔
51
            getenv('PHP_CS_FIXER_FUTURE_MODE'),
4✔
52
            \FILTER_VALIDATE_BOOL,
4✔
53
        );
4✔
54
    }
55

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

66
        $message = $futureException->getMessage();
1✔
67

68
        self::$deprecations[$message] = true;
1✔
69
        @trigger_error($message, \E_USER_DEPRECATED);
1✔
70
    }
71

72
    /**
73
     * @return list<string>
74
     */
75
    public static function getTriggeredDeprecations(): array
76
    {
77
        $triggeredDeprecations = array_keys(self::$deprecations);
2✔
78
        sort($triggeredDeprecations);
2✔
79

80
        return $triggeredDeprecations;
2✔
81
    }
82

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

98
    /**
99
     * @template T
100
     *
101
     * @param T $new
102
     * @param T $old
103
     *
104
     * @return T
105
     */
106
    private static function getNewOrOld($new, $old)
107
    {
108
        return self::isFutureModeEnabled() ? $new : $old;
2✔
109
    }
110
}
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