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

mixerapi / core / 18703470333

22 Oct 2025 02:27AM UTC coverage: 90.0% (+0.08%) from 89.922%
18703470333

Pull #9

github

web-flow
Merge 0d87c648f into 4ddf2a5a5
Pull Request #9: Update dependency to deal with deprecations in depedency tree

2 of 3 new or added lines in 3 files covered. (66.67%)

1 existing line in 1 file now uncovered.

117 of 130 relevant lines covered (90.0%)

1.83 hits per line

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

87.1
/src/Utility/NamespaceUtility.php
1
<?php
2
declare(strict_types=1);
3

4
namespace MixerApi\Core\Utility;
5

6
use Cake\Collection\Collection;
7
use Cake\Core\Configure;
8
use Cake\Core\Plugin;
9
use Kcs\ClassFinder\Finder\ComposerFinder;
10
use RuntimeException;
11

12
class NamespaceUtility
13
{
14
    /**
15
     * Finds classes using the $namespace argument and returns an array of namespaces as strings.
16
     *
17
     * @param string|null $namespace A namespace such as `App\Controller`, if null, the `App.namespace` config is used.
18
     * @param array<string> $paths A list of absolute paths to load classes from
19
     * @return array<string>
20
     */
21
    public static function findClasses(?string $namespace = null, array $paths = []): array
22
    {
23
        $namespace = $namespace ?? Configure::read('App.namespace');
4✔
24
        if (str_starts_with($namespace, '\\')) {
4✔
25
            $namespace = substr($namespace, 1, strlen($namespace));
2✔
26
        }
27
        if (str_ends_with($namespace, '\\')) {
4✔
28
            $namespace = substr($namespace, 0, strlen($namespace) - 1);
2✔
29
        }
30

31
        if (empty($paths)) {
4✔
32
            $paths = [APP];
4✔
33

34
            /** @var \Cake\Core\BasePlugin $plugin */
35
            foreach (Plugin::getCollection() as $plugin) {
4✔
36
                if (str_contains('/vendor/', $plugin->getClassPath())) {
×
37
                    continue;
×
38
                }
39
                $paths[] = $plugin->getClassPath();
×
40
            }
41
        }
42

43
        $finder = (new ComposerFinder())
4✔
44
            ->useAutoloading(false)
4✔
45
            ->inNamespace($namespace)
4✔
46
            ->in($paths);
4✔
47
        $classes = [];
4✔
48
        foreach ($finder as $className => $reflector) {
4✔
49
            $classes[] = $className;
4✔
50
        }
51

52
        return array_map(function (string $namespace) {
4✔
53
            if (!str_starts_with($namespace, '\\')) {
4✔
54
                return '\\' . $namespace;
4✔
55
            }
56

UNCOV
57
            return $namespace;
×
58
        }, $classes);
4✔
59
    }
60

61
    /**
62
     * Performs a non-recursive search for the classes shortname in the given namespace
63
     *
64
     * @param string $namespace The namespace to search in
65
     * @param string $shortName The short name of the class
66
     * @return string
67
     * @throws \RuntimeException
68
     */
69
    public static function findClass(string $namespace, string $shortName): string
70
    {
71
        $classes = NamespaceUtility::findClasses($namespace);
2✔
72

73
        $results = (new Collection($classes))->filter(function ($class) use ($shortName) {
2✔
74
            $pieces = explode('\\', $class);
2✔
75

76
            return end($pieces) == $shortName;
2✔
77
        });
2✔
78

79
        if (!$results->count()) {
2✔
80
            throw new RuntimeException("Class not found for `$shortName` in `$namespace`");
1✔
81
        }
82

83
        return $results->first();
1✔
84
    }
85
}
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