Completed
Push — master ( 111167...d069a6 )
by Jakub
01:41
created

ComposerTestsSuitesFinder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 15
c 1
b 0
f 1
dl 0
loc 23
ccs 0
cts 15
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSuites() 0 20 6
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace MyTester;
7
8
use ReflectionClass;
9
use ReflectionException;
10
11
/**
12
 * @author Jakub Konečný
13
 * @internal
14
 */
15
class ComposerTestsSuitesFinder implements ITestsSuitesFinder
16
{
17
18
    public function getSuites(string $folder): array
19
    {
20
        $suites = [];
21
        $folder = (string) realpath($folder);
22
        $classMap = require \findVendorDirectory() . "/composer/autoload_classmap.php";
23
        foreach ($classMap as $class => $file) {
24
            $file = (string) realpath($file);
25
            if (!str_starts_with($file, $folder)) {
26
                continue;
27
            }
28
            try {
29
                $reflection = new ReflectionClass($class);
30
            } catch (ReflectionException $e) {
31
                continue;
32
            }
33
            if (!$reflection->isAbstract() && $reflection->isSubclassOf(TestCase::class)) {
34
                $suites[] = $reflection->getName();
35
            }
36
        }
37
        return $suites;
38
    }
39
}
40