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

keradus / PHP-CS-Fixer / 22221749797

20 Feb 2026 11:06AM UTC coverage: 92.928% (-0.03%) from 92.957%
22221749797

push

github

web-flow
fix: `NoUnusedImportsFixer` - do not remove constant types (#9442)

3 of 3 new or added lines in 1 file covered. (100.0%)

139 existing lines in 4 files now uncovered.

29305 of 31535 relevant lines covered (92.93%)

44.03 hits per line

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

90.0
/src/Runner/FileFilterIterator.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\Runner;
16

17
use PhpCsFixer\Cache\CacheManagerInterface;
18
use PhpCsFixer\FileReader;
19
use PhpCsFixer\Runner\Event\FileProcessed;
20
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
21
use Symfony\Contracts\EventDispatcher\Event;
22

23
/**
24
 * @internal
25
 *
26
 * @extends \FilterIterator<mixed, \SplFileInfo, \Iterator<mixed, \SplFileInfo>>
27
 *
28
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
29
 *
30
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
31
 */
32
final class FileFilterIterator extends \FilterIterator
33
{
34
    private ?EventDispatcherInterface $eventDispatcher;
35

36
    private CacheManagerInterface $cacheManager;
37

38
    /**
39
     * @var array<string, bool>
40
     */
41
    private array $visitedElements = [];
42

43
    /**
44
     * @param iterable<\SplFileInfo> $iterator
45
     */
46
    public function __construct(
47
        iterable $iterator,
48
        ?EventDispatcherInterface $eventDispatcher,
49
        CacheManagerInterface $cacheManager
50
    ) {
51
        if (!$iterator instanceof \Iterator) {
9✔
52
            $iterator = new \IteratorIterator(
×
UNCOV
53
                $iterator instanceof \Traversable ? $iterator : new \ArrayIterator($iterator),
×
UNCOV
54
            );
×
55
        }
56

57
        parent::__construct($iterator);
9✔
58

59
        $this->eventDispatcher = $eventDispatcher;
9✔
60
        $this->cacheManager = $cacheManager;
9✔
61
    }
62

63
    public function accept(): bool
64
    {
65
        $file = $this->current();
9✔
66
        if (!$file instanceof \SplFileInfo) {
9✔
67
            throw new \RuntimeException(
1✔
68
                \sprintf(
1✔
69
                    'Expected instance of "\SplFileInfo", got "%s".',
1✔
70
                    get_debug_type($file),
1✔
71
                ),
1✔
72
            );
1✔
73
        }
74

75
        $path = $file->isLink() ? $file->getPathname() : $file->getRealPath();
8✔
76

77
        if (isset($this->visitedElements[$path])) {
8✔
78
            return false;
2✔
79
        }
80

81
        $this->visitedElements[$path] = true;
8✔
82

83
        if (!$file->isFile() || $file->isLink()) {
8✔
84
            return false;
2✔
85
        }
86

87
        $content = FileReader::createSingleton()->read($path);
7✔
88

89
        // mark as skipped:
90
        if (
91
            // empty file
92
            '' === $content
7✔
93
            // file that does not need fixing due to cache
94
            || !$this->cacheManager->needFixing($file->getPathname(), $content)
7✔
95
        ) {
96
            $this->dispatchEvent(FileProcessed::NAME, new FileProcessed(FileProcessed::STATUS_SKIPPED));
3✔
97

98
            return false;
3✔
99
        }
100

101
        return true;
4✔
102
    }
103

104
    private function dispatchEvent(string $name, Event $event): void
105
    {
106
        if (null === $this->eventDispatcher) {
3✔
107
            return;
1✔
108
        }
109

110
        $this->eventDispatcher->dispatch($event, $name);
2✔
111
    }
112
}
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