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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

91.18
/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
    /**
26
     * @var array<string, array<class-string, \ReflectionClass>>
27
     */
28
    private static array $localCache;
29

30
    private function __construct()
31
    {
32
    }
×
33

34
    /**
35
     * @param string[] $directories
36
     * @param string   $ignoreRegex Laravel uses (?!.*Test\.php$) to avoid loading pest class tests
37
     *
38
     * @return array<class-string, \ReflectionClass>
39
     */
40
    public static function getReflectionClassesFromDirectories(array $directories, string $ignoreRegex = ''): array
41
    {
UNCOV
42
        $id = hash('xxh3', implode('', $directories));
4✔
UNCOV
43
        if (isset(self::$localCache[$id])) {
4✔
UNCOV
44
            return self::$localCache[$id];
2✔
45
        }
46

UNCOV
47
        $includedFiles = [];
2✔
UNCOV
48
        foreach ($directories as $path) {
2✔
UNCOV
49
            $iterator = new \RegexIterator(
2✔
UNCOV
50
                new \RecursiveIteratorIterator(
2✔
UNCOV
51
                    new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
2✔
UNCOV
52
                    \RecursiveIteratorIterator::LEAVES_ONLY
2✔
UNCOV
53
                ),
2✔
UNCOV
54
                '/^'.$ignoreRegex.'.+\.php$/i',
2✔
UNCOV
55
                \RecursiveRegexIterator::GET_MATCH
2✔
UNCOV
56
            );
2✔
57

UNCOV
58
            foreach ($iterator as $file) {
2✔
UNCOV
59
                $sourceFile = $file[0];
2✔
60

UNCOV
61
                if (!preg_match('(^phar:)i', (string) $sourceFile)) {
2✔
UNCOV
62
                    $sourceFile = realpath($sourceFile);
2✔
63
                }
64

65
                try {
UNCOV
66
                    require_once $sourceFile;
2✔
67
                } catch (\Throwable) {
×
68
                    // invalid PHP file (example: missing parent class)
69
                    continue;
×
70
                }
71

UNCOV
72
                $includedFiles[$sourceFile] = true;
2✔
73
            }
74
        }
75

UNCOV
76
        $sortedClasses = get_declared_classes();
2✔
UNCOV
77
        sort($sortedClasses);
2✔
UNCOV
78
        $sortedInterfaces = get_declared_interfaces();
2✔
UNCOV
79
        sort($sortedInterfaces);
2✔
UNCOV
80
        $declared = [...$sortedClasses, ...$sortedInterfaces];
2✔
UNCOV
81
        $ret = [];
2✔
UNCOV
82
        foreach ($declared as $className) {
2✔
UNCOV
83
            $reflectionClass = new \ReflectionClass($className);
2✔
UNCOV
84
            $sourceFile = $reflectionClass->getFileName();
2✔
UNCOV
85
            if (isset($includedFiles[$sourceFile])) {
2✔
UNCOV
86
                $ret[$className] = $reflectionClass;
2✔
87
            }
88
        }
89

UNCOV
90
        return self::$localCache[$id] = $ret;
2✔
91
    }
92
}
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