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

daycry / class-finder / 16724626674

04 Aug 2025 01:32PM UTC coverage: 82.262% (-12.2%) from 94.493%
16724626674

push

github

web-flow
Update php.yml

320 of 389 relevant lines covered (82.26%)

3.29 hits per line

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

90.91
/src/Libraries/PSR4/PSR4Finder.php
1
<?php
2

3
namespace Daycry\ClassFinder\Libraries\PSR4;
4

5
use Daycry\ClassFinder\ClassFinder;
6
use Daycry\ClassFinder\Interfaces\FinderInterface;
7

8
class PSR4Finder implements FinderInterface
9
{
10
    private PSR4Factory $factory;
11

12
    public function __construct()
13
    {
14
        $this->factory = new PSR4Factory();
2✔
15
    }
16

17
    public function getPriority(): int
18
    {
19
        return 1; // High priority for PSR4
×
20
    }
21

22
    public function findClasses(string $namespace, $options): array
23
    {
24
        $applicableNamespaces = [];
2✔
25

26
        if ($options & ClassFinder::RECURSIVE_MODE) {
2✔
27
            $applicableNamespaces = $this->findAllApplicableNamespaces($namespace);
1✔
28
        }
29

30
        if (empty($applicableNamespaces)) {
2✔
31
            $bestNamespace = $this->findBestPSR4Namespace($namespace);
1✔
32
            if ($bestNamespace !== null) {
1✔
33
                $applicableNamespaces = [$bestNamespace];
1✔
34
            }
35
        }
36

37
        $classes = [];
2✔
38

39
        foreach ($applicableNamespaces as $psr4Namespace) {
2✔
40
            if ($psr4Namespace instanceof PSR4Namespace) {
2✔
41
                $classes = array_merge($classes, $psr4Namespace->findClasses($namespace, $options));
2✔
42
            }
43
        }
44

45
        return $classes;
2✔
46
    }
47

48
    public function isNamespaceKnown(string $namespace): bool
49
    {
50
        $composerNamespaces = $this->factory->getPSR4Namespaces();
2✔
51

52
        foreach ($composerNamespaces as $psr4Namespace) {
2✔
53
            if ($psr4Namespace->knowsNamespace($namespace)) {
2✔
54
                return true;
2✔
55
            }
56
        }
57

58
        return false;
×
59
    }
60

61
    /**
62
     * @return list<PSR4Namespace>
63
     */
64
    private function findAllApplicableNamespaces(string $namespace): array
65
    {
66
        $composerNamespaces = $this->factory->getPSR4Namespaces();
1✔
67

68
        return array_filter($composerNamespaces, static fn (PSR4Namespace $potentialNamespace) => $potentialNamespace->isAcceptableNamespaceRecursiveMode($namespace));
1✔
69
    }
70

71
    private function findBestPSR4Namespace(string $namespace): ?PSR4Namespace
72
    {
73
        $composerNamespaces = $this->factory->getPSR4Namespaces();
1✔
74

75
        $acceptableNamespaces = array_filter($composerNamespaces, static fn (PSR4Namespace $potentialNamespace) => $potentialNamespace->isAcceptableNamespace($namespace));
1✔
76

77
        if (empty($acceptableNamespaces)) {
1✔
78
            return null;
×
79
        }
80

81
        $bestNamespace           = null;
1✔
82
        $highestMatchingSegments = 0;
1✔
83

84
        foreach ($acceptableNamespaces as $potentialNamespace) {
1✔
85
            $matchingSegments = $potentialNamespace->countMatchingNamespaceSegments($namespace);
1✔
86

87
            if ($matchingSegments > $highestMatchingSegments) {
1✔
88
                $highestMatchingSegments = $matchingSegments;
1✔
89
                $bestNamespace           = $potentialNamespace;
1✔
90
            }
91
        }
92

93
        return $bestNamespace;
1✔
94
    }
95
}
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