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

ComposerTestsSuitesFinder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

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

1 Method

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