Passed
Pull Request — master (#53)
by Kevin
20:12
created

ModelFactoryManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 21
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
    public function __construct(iterable $factories)
18
    {
19
        $this->factories = $factories;
20
    }
21
22
    public function create(string $class): ModelFactory
23
    {
24
        foreach ($this->factories as $factory) {
25
            if ($class === \get_class($factory)) {
26
                return $factory;
27
            }
28
        }
29
30
        return new $class();
31
    }
32
}
33