FiniteStateMachineFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A build() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dflydev\FiniteStateMachine;
6
7
use Dflydev\FiniteStateMachine\Contracts\EventDispatcher;
8
use Dflydev\FiniteStateMachine\Graph\GraphResolver;
9
use Dflydev\FiniteStateMachine\ObjectProxy\ObjectProxyResolver;
10
11
class FiniteStateMachineFactory
12
{
13
    private GraphResolver $graphResolver;
14
    private ObjectProxyResolver $objectProxyResolver;
15
    private ?EventDispatcher $eventDispatcher;
16
17 21
    public function __construct(
18
        GraphResolver $graphResolver,
19
        ObjectProxyResolver $objectProxyResolver,
20
        ?EventDispatcher $eventDispatcher = null
21
    ) {
22 21
        $this->graphResolver = $graphResolver;
23 21
        $this->objectProxyResolver = $objectProxyResolver;
24 21
        $this->eventDispatcher = $eventDispatcher;
25 21
    }
26
27 21
    public function build(object $object, string $graph = 'default'): FiniteStateMachine
28
    {
29 21
        $graph = $this->graphResolver->resolve($object, $graph);
30 19
        $objectProxy = $this->objectProxyResolver->resolve($object, $graph->objectProxyOptions());
31
32 19
        return new FiniteStateMachine($objectProxy, $graph, $this->eventDispatcher);
33
    }
34
}
35