Completed
Push — master ( 3bd4e2...776f46 )
by Jesse
04:06
created

BasicProxyFactory::create()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Proxy;
4
5
use InvalidArgumentException;
6
use function is_a;
7
use function sprintf;
8
9
/**
10
 * BasicProxyFactory.
11
 *
12
 * @author Stratadox
13
 */
14
final class BasicProxyFactory implements ProxyFactory
15
{
16
    private $class;
17
    private $loader;
18
19
    private function __construct(
20
        string $class,
21
        ProxyLoader $loader
22
    ) {
23
        $this->class = $class;
24
        $this->loader = $loader;
25
        if (!is_a($class, Proxy::class, true)) {
26
            throw new InvalidArgumentException(sprintf(
27
                'Cannot use non-proxy class `%s` as proxy.',
28
                $class
29
            ));
30
        }
31
    }
32
33
    public static function for(string $class, ProxyLoader $loader): ProxyFactory
34
    {
35
        return new self($class, $loader);
36
    }
37
38
    public function create(array $knownData = []): Proxy
39
    {
40
        return new $this->class($this->loader, $knownData);
41
    }
42
}
43