Completed
Push — master ( 1e2cfa...28995d )
by Eric
04:38
created

EventClassMetadataFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 44
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getClassMetadata() 0 18 2
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Mapping\Factory;
13
14
use Ivory\Serializer\Event\ClassMetadataLoadEvent;
15
use Ivory\Serializer\Event\ClassMetadataNotFoundEvent;
16
use Ivory\Serializer\Event\SerializerEvents;
17
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
class EventClassMetadataFactory implements ClassMetadataFactoryInterface
23
{
24
    /**
25
     * @var ClassMetadataFactoryInterface
26
     */
27
    private $factory;
28
29
    /**
30
     * @var EventDispatcherInterface
31
     */
32
    private $dispatcher;
33
34
    /**
35
     * @param ClassMetadataFactoryInterface $factory
36
     * @param EventDispatcherInterface      $dispatcher
37
     */
38 8
    public function __construct(ClassMetadataFactoryInterface $factory, EventDispatcherInterface $dispatcher)
39
    {
40 8
        $this->factory = $factory;
41 8
        $this->dispatcher = $dispatcher;
42 8
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 8
    public function getClassMetadata($class)
48
    {
49 8
        $classMetadata = $this->factory->getClassMetadata($class);
50
51 8
        if ($classMetadata === null) {
52 4
            $this->dispatcher->dispatch(
53 4
                SerializerEvents::CLASS_METADATA_NOT_FOUND,
54 4
                $event = new ClassMetadataNotFoundEvent($class)
55 2
            );
56 2
        } else {
57 4
            $this->dispatcher->dispatch(
58 4
                SerializerEvents::CLASS_METADATA_LOAD,
59 4
                $event = new ClassMetadataLoadEvent($classMetadata)
60 2
            );
61
        }
62
63 8
        return $event->getClassMetadata();
64
    }
65
}
66