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

api-platform / core / 11271860720

10 Oct 2024 10:04AM UTC coverage: 7.84% (+0.007%) from 7.833%
11271860720

push

github

soyuka
Merge 3.4

0 of 34 new or added lines in 5 files covered. (0.0%)

11160 existing lines in 381 files now uncovered.

12955 of 165237 relevant lines covered (7.84%)

27.06 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
    {
UNCOV
31
        foreach ($directories as $path) {
12✔
UNCOV
32
            $iterator = new \RegexIterator(
12✔
UNCOV
33
                new \RecursiveIteratorIterator(
12✔
UNCOV
34
                    new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
12✔
UNCOV
35
                    \RecursiveIteratorIterator::LEAVES_ONLY
12✔
UNCOV
36
                ),
12✔
UNCOV
37
                '/^.+\.php$/i',
12✔
UNCOV
38
                \RecursiveRegexIterator::GET_MATCH
12✔
UNCOV
39
            );
12✔
40

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

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

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

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

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