Completed
Pull Request — master (#84)
by Daniel
02:13
created

EventDispatchingGridMetadataFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getGridMetadata() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
use Psi\Component\Grid\Event\GridMetadataEvent;
8
use Psi\Component\Grid\Metadata\GridMetadata;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
11
class EventDispatchingGridMetadataFactory implements GridMetadataFactoryInterface
12
{
13
    /**
14
     * @var GridMetadataFactoryInterface
15
     */
16
    private $innerFactory;
17
18
    /**
19
     * @var EventDispatcherInterface
20
     */
21
    private $eventDispatcher;
22
23
    public function __construct(
24
        GridMetadataFactoryInterface $innerFactory,
25
        EventDispatcherInterface $eventDispatcher
26
    ) {
27
        $this->innerFactory = $innerFactory;
28
        $this->eventDispatcher = $eventDispatcher;
29
    }
30
31
    public function getGridMetadata(string $classFqn, string $variant): GridMetadata
32
    {
33
        $gridMetadata = $this->innerFactory->getGridMetadata($classFqn, $variant);
34
        $event = new GridMetadataEvent($gridMetadata);
35
        $this->eventDispatcher->dispatch(Events::METADATA_LOADED, $event);
36
37
        return $event->getMetadata();
38
    }
39
}
40