Passed
Push — master ( aa061c...2e1140 )
by Jakub
02:07
created

ContainerSuiteFactory::create()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
ccs 5
cts 5
cp 1
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MyTester\Bridges\NetteDI;
6
7
use MyTester\InvalidTestCaseException;
8
use MyTester\TestCase;
9
10
/**
11
 * @author Jakub Konečný
12
 * @internal
13
 */
14
final class ContainerSuiteFactory implements \MyTester\ITestSuiteFactory
15
{
16
    /** @var TestCase[] */
17
    private array $suites;
18
19
    /**
20
     * @param TestCase[] $suites
21
     */
22 1
    public function __construct(array $suites)
23
    {
24 1
        $this->suites = $suites;
25
    }
26
27
  /**
28
   * @param class-string $className
29
   */
30 1
    public function create(string $className): TestCase
31
    {
32 1
        foreach ($this->suites as $suite) {
33 1
            if ($suite instanceof $className && $suite instanceof TestCase) {
34 1
                return $suite;
35
            }
36
        }
37 1
        throw new InvalidTestCaseException("$className is not a descendant of " . TestCase::class . ".");
38
    }
39
}
40