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

api-platform / core / 11176269767

04 Oct 2024 08:02AM UTC coverage: 7.725% (+0.3%) from 7.441%
11176269767

push

github

soyuka
chore: remove useless require-dev

12744 of 164973 relevant lines covered (7.72%)

27.04 hits per line

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

89.29
/src/Metadata/Util/ReflectionClassRecursiveIterator.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Metadata\Util;
15

16
/**
17
 * Gets reflection classes for php files in the given directories.
18
 *
19
 * @author Antoine Bluchet <soyuka@gmail.com>
20
 *
21
 * @internal
22
 */
23
final class ReflectionClassRecursiveIterator
24
{
25
    private function __construct()
26
    {
27
    }
×
28

29
    public static function getReflectionClassesFromDirectories(array $directories): \Iterator
30
    {
31
        foreach ($directories as $path) {
12✔
32
            $iterator = new \RegexIterator(
12✔
33
                new \RecursiveIteratorIterator(
12✔
34
                    new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
12✔
35
                    \RecursiveIteratorIterator::LEAVES_ONLY
12✔
36
                ),
12✔
37
                '/^.+\.php$/i',
12✔
38
                \RecursiveRegexIterator::GET_MATCH
12✔
39
            );
12✔
40

41
            foreach ($iterator as $file) {
12✔
42
                $sourceFile = $file[0];
12✔
43

44
                if (!preg_match('(^phar:)i', (string) $sourceFile)) {
12✔
45
                    $sourceFile = realpath($sourceFile);
12✔
46
                }
47

48
                try {
49
                    require_once $sourceFile;
12✔
50
                } catch (\Throwable) {
×
51
                    // invalid PHP file (example: missing parent class)
52
                    continue;
×
53
                }
54

55
                $includedFiles[$sourceFile] = true;
12✔
56
            }
57
        }
58

59
        $sortedClasses = get_declared_classes();
12✔
60
        sort($sortedClasses);
12✔
61
        $sortedInterfaces = get_declared_interfaces();
12✔
62
        sort($sortedInterfaces);
12✔
63
        $declared = [...$sortedClasses, ...$sortedInterfaces];
12✔
64
        foreach ($declared as $className) {
12✔
65
            $reflectionClass = new \ReflectionClass($className);
12✔
66
            $sourceFile = $reflectionClass->getFileName();
12✔
67
            if (isset($includedFiles[$sourceFile])) {
12✔
68
                yield $className => $reflectionClass;
12✔
69
            }
70
        }
71
    }
72
}
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

© 2025 Coveralls, Inc