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

ModelFactoryManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 3
A __construct() 0 3 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