Passed
Push — master ( 08ad67...bd34c5 )
by Jesse
02:05
created

DeserializingProxyFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A using() 0 5 1
A create() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Proxy;
4
5
use Stratadox\Deserializer\CannotDeserialize;
6
use Stratadox\Deserializer\Deserializes;
7
8
final class DeserializingProxyFactory implements ProxyFactory
9
{
10
    private $deserializer;
11
    private $loader;
12
13
    private function __construct(Deserializes $deserializer, ProxyLoader $loader)
14
    {
15
        $this->deserializer = $deserializer;
16
        $this->loader = $loader;
17
    }
18
19
    public static function using(
20
        Deserializes $deserializer,
21
        ProxyLoader $loader
22
    ): ProxyFactory {
23
        return new self($deserializer, $loader);
24
    }
25
26
    /** @inheritdoc */
27
    public function create(array $knownData = []): Proxy
28
    {
29
        try {
30
            return $this->deserializer->from([
31
                'loader' => $this->loader,
32
                'knownData' => $knownData,
33
            ]);
34
        } catch (CannotDeserialize $exception) {
35
            throw ProxyDeserializationFailed::encountered($exception);
36
        }
37
    }
38
}
39