Passed
Pull Request — master (#53)
by Kevin
16:24
created

ModelFactoryRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Zenstruck\Foundry;
4
5
/**
6
 * @internal
7
 *
8
 * @author Kevin Bond <[email protected]>
9
 */
10
final class ModelFactoryRegistry
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 get(string $class): ?ModelFactory
23
    {
24
        foreach ($this->factories as $factory) {
25
            if ($class === \get_class($factory)) {
26
                return $factory;
27
            }
28
        }
29
30
        return null;
31
    }
32
}
33