Passed
Push — master ( ddb2f3...fd433b )
by Kevin
03:42
created

ModelFactoryManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Zenstruck\Foundry;
4
5
/**
6
 * @internal
7
 *
8
 * @author Kevin Bond <[email protected]>
9
 */
10
final class ModelFactoryManager
11
{
12
    private $factories;
13
14
    /**
15
     * @param ModelFactory[] $factories
16
     */
17 692
    public function __construct(iterable $factories)
18
    {
19 692
        $this->factories = $factories;
20 692
    }
21
22 417
    public function create(string $class): ModelFactory
23
    {
24 417
        foreach ($this->factories as $factory) {
25 156
            if ($class === \get_class($factory)) {
26 60
                return $factory;
27
            }
28
        }
29
30 399
        return new $class();
31
    }
32
}
33