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

api-platform / core / 10523796051

23 Aug 2024 10:00AM UTC coverage: 6.984% (-0.7%) from 7.707%
10523796051

push

github

dunglas
chore(laravel): remove duplicated ItemNormalizer definition

11317 of 162035 relevant lines covered (6.98%)

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

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

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

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

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

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