Completed
Pull Request — master (#8)
by Daniel
04:09 queued 01:56
created

EventDispatchingAgent::getCapabilities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Psi\Component\ObjectAgent;
4
5
use Psi\Component\ObjectAgent\Event\ObjectEvent;
6
use Psi\Component\ObjectAgent\Query\Query;
7
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8
9
class EventDispatchingAgent implements AgentInterface
10
{
11
    private $dispatcher;
12
    private $agent;
13
14
    public function __construct(
15
        AgentInterface $agent,
16
        EventDispatcherInterface $dispatcher
17
    ) {
18
        $this->agent = $agent;
19
        $this->dispatcher = $dispatcher;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getCapabilities(): Capabilities
26
    {
27
        return $this->agnet->getCapabilities();
0 ignored issues
show
Bug introduced by
The property agnet does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function find($identifier, string $class = null)
34
    {
35
        return $this->agent->find($identifier, $class);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function save($object)
42
    {
43
        $this->dispatch(Events::PRE_SAVE, $object);
44
        $this->agent->save($object);
45
        $this->dispatch(Events::POST_SAVE, $object);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function query(Query $query): \Traversable
52
    {
53
        return $this->agent->query($query);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function delete($object)
60
    {
61
        $this->dispatch(Events::PRE_DELETE, $object);
62
        $this->agent->delete($object);
63
        $this->dispatch(Events::POST_DELETE, $object);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getIdentifier($object)
70
    {
71
        return $this->agent->getIdentifier($object);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function supports(string $class): bool
78
    {
79
        return $this->agent->supports($class);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function setParent($object, $parent)
86
    {
87
        return $this->agent->setParent($object, $parent);
88
    }
89
90
    private function dispatch(string $eventName, $object)
91
    {
92
        $this->dispatcher->dispatch($eventName, new ObjectEvent($this->agent, $object));
93
    }
94
}
95