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

keradus / PHP-CS-Fixer / 19958239208

05 Dec 2025 09:13AM UTC coverage: 93.181% (-1.0%) from 94.158%
19958239208

push

github

keradus
chore: .php-cs-fixer.dist.php - remove no longer needed rule, 'expectedDeprecation' annotation does not exist for long time

28928 of 31045 relevant lines covered (93.18%)

44.49 hits per line

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

86.84
/src/Fixer/ConfigurableFixerTrait.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\Fixer;
16

17
use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
18
use PhpCsFixer\ConfigurationException\InvalidForEnvFixerConfigurationException;
19
use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException;
20
use PhpCsFixer\Console\Application;
21
use PhpCsFixer\FixerConfiguration\DeprecatedFixerOption;
22
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
23
use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException;
24
use PhpCsFixer\Future;
25
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
26
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
27

28
/**
29
 * @internal
30
 *
31
 * @template TFixerInputConfig of array<string, mixed>
32
 * @template TFixerComputedConfig of array<string, mixed>
33
 *
34
 * @phpstan-require-implements ConfigurableFixerInterface<TFixerInputConfig, TFixerComputedConfig>
35
 *
36
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
37
 *
38
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
39
 */
40
trait ConfigurableFixerTrait
41
{
42
    /**
43
     * @var null|TFixerComputedConfig
44
     */
45
    protected ?array $configuration = null;
46

47
    private ?FixerConfigurationResolverInterface $configurationDefinition = null;
48

49
    /**
50
     * @param TFixerInputConfig $configuration
51
     */
52
    final public function configure(array $configuration): void
53
    {
54
        $this->configurePreNormalisation($configuration);
13,567✔
55

56
        foreach ($this->getConfigurationDefinition()->getOptions() as $option) {
13,567✔
57
            if (!$option instanceof DeprecatedFixerOption) {
13,567✔
58
                continue;
13,355✔
59
            }
60

61
            $name = $option->getName();
261✔
62
            if (\array_key_exists($name, $configuration)) {
261✔
63
                Future::triggerDeprecation(new \InvalidArgumentException(\sprintf(
94✔
64
                    'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
94✔
65
                    $name,
94✔
66
                    $this->getName(),
94✔
67
                    Application::getMajorVersion() + 1,
94✔
68
                    str_replace('`', '"', $option->getDeprecationMessage())
94✔
69
                )));
94✔
70
            }
71
        }
72

73
        try {
74
            $this->configuration = $this->getConfigurationDefinition()->resolve($configuration); // @phpstan-ignore-line ->configuration typehint is autogenerated base on ConfigurationDefinition
13,567✔
75
        } catch (MissingOptionsException $exception) {
242✔
76
            throw new RequiredFixerConfigurationException(
77✔
77
                $this->getName(),
77✔
78
                \sprintf('Missing required configuration: %s', $exception->getMessage()),
77✔
79
                $exception
77✔
80
            );
77✔
81
        } catch (InvalidOptionsForEnvException $exception) {
172✔
82
            throw new InvalidForEnvFixerConfigurationException(
×
83
                $this->getName(),
×
84
                \sprintf('Invalid configuration for env: %s', $exception->getMessage()),
×
85
                $exception
×
86
            );
×
87
        } catch (ExceptionInterface $exception) {
172✔
88
            throw new InvalidFixerConfigurationException(
164✔
89
                $this->getName(),
164✔
90
                \sprintf('Invalid configuration: %s', $exception->getMessage()),
164✔
91
                $exception
164✔
92
            );
164✔
93
        }
94

95
        $this->configurePostNormalisation();
13,549✔
96
    }
97

98
    final public function getConfigurationDefinition(): FixerConfigurationResolverInterface
99
    {
100
        if (null === $this->configurationDefinition) {
13,567✔
101
            $this->configurationDefinition = $this->createConfigurationDefinition();
13,567✔
102
        }
103

104
        return $this->configurationDefinition;
13,567✔
105
    }
106

107
    abstract public function getName(): string;
108

109
    /**
110
     * One can override me.
111
     *
112
     * @param TFixerInputConfig $configuration
113
     */
114
    protected function configurePreNormalisation(array &$configuration): void
115
    {
116
        // 🤔 ideally this method won't be needed, maybe we can remove it over time
117
    }
13,478✔
118

119
    /**
120
     * One can override me.
121
     */
122
    protected function configurePostNormalisation(): void
123
    {
124
        // 🤔 ideally this method won't be needed, maybe we can remove it over time
125
    }
7,059✔
126

127
    abstract protected function createConfigurationDefinition(): FixerConfigurationResolverInterface;
128
}
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