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

keradus / PHP-CS-Fixer / 17319949156

29 Aug 2025 09:20AM UTC coverage: 94.696% (-0.05%) from 94.744%
17319949156

push

github

keradus
CS

28333 of 29920 relevant lines covered (94.7%)

45.63 hits per line

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

54.55
/src/AbstractFixer.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
use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException;
18
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
19
use PhpCsFixer\Fixer\FixerInterface;
20
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
21
use PhpCsFixer\Tokenizer\Tokens;
22

23
/**
24
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
25
 *
26
 * @internal
27
 *
28
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
29
 */
30
abstract class AbstractFixer implements FixerInterface
31
{
32
    protected WhitespacesFixerConfig $whitespacesConfig;
33

34
    public function __construct()
35
    {
36
        if ($this instanceof ConfigurableFixerInterface) {
3✔
37
            try {
38
                $this->configure([]);
×
39
            } catch (RequiredFixerConfigurationException $e) {
×
40
                // ignore
41
            }
42
        }
43

44
        if ($this instanceof WhitespacesAwareFixerInterface) {
3✔
45
            $this->whitespacesConfig = $this->getDefaultWhitespacesFixerConfig();
1✔
46
        }
47
    }
48

49
    final public function fix(\SplFileInfo $file, Tokens $tokens): void
50
    {
51
        if ($this instanceof ConfigurableFixerInterface && property_exists($this, 'configuration') && null === $this->configuration) {
×
52
            throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
×
53
        }
54

55
        if (0 < $tokens->count() && $this->isCandidate($tokens) && $this->supports($file)) {
×
56
            $this->applyFix($file, $tokens);
×
57
        }
58
    }
59

60
    public function isRisky(): bool
61
    {
62
        return false;
1✔
63
    }
64

65
    public function getName(): string
66
    {
67
        $nameParts = explode('\\', static::class);
×
68
        $name = substr(end($nameParts), 0, -\strlen('Fixer'));
×
69

70
        return Utils::camelCaseToUnderscore($name);
×
71
    }
72

73
    public function getPriority(): int
74
    {
75
        return 0;
×
76
    }
77

78
    public function supports(\SplFileInfo $file): bool
79
    {
80
        return true;
1✔
81
    }
82

83
    public function setWhitespacesConfig(WhitespacesFixerConfig $config): void
84
    {
85
        if (!$this instanceof WhitespacesAwareFixerInterface) {
2✔
86
            throw new \LogicException('Cannot run method for class not implementing "PhpCsFixer\Fixer\WhitespacesAwareFixerInterface".');
1✔
87
        }
88

89
        $this->whitespacesConfig = $config;
1✔
90
    }
91

92
    abstract protected function applyFix(\SplFileInfo $file, Tokens $tokens): void;
93

94
    private function getDefaultWhitespacesFixerConfig(): WhitespacesFixerConfig
95
    {
96
        static $defaultWhitespacesFixerConfig = null;
1✔
97

98
        if (null === $defaultWhitespacesFixerConfig) {
1✔
99
            $defaultWhitespacesFixerConfig = new WhitespacesFixerConfig('    ', "\n");
1✔
100
        }
101

102
        return $defaultWhitespacesFixerConfig;
1✔
103
    }
104
}
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