Passed
Push — dev_2x ( 3e8772...896177 )
by Adrian
06:45
created

Events   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 24
c 1
b 0
f 0
dl 0
loc 66
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A onDeleting() 0 6 1
A onSaving() 0 6 1
A getName() 0 3 1
A __construct() 0 4 1
A onSaved() 0 6 1
A onDeleted() 0 6 1
A onNewQuery() 0 6 1
A onNewEntity() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Behaviour;
5
6
use Psr\EventDispatcher\EventDispatcherInterface;
7
use Sirius\Orm\Contract\EntityInterface;
8
use Sirius\Orm\Event\DeletedEntity;
9
use Sirius\Orm\Event\DeletingEntity;
10
use Sirius\Orm\Event\NewEntity;
11
use Sirius\Orm\Event\NewMapperQuery;
12
use Sirius\Orm\Event\SavedEntity;
13
use Sirius\Orm\Event\SavingEntity;
14
use Sirius\Orm\Mapper;
15
use Sirius\Orm\Query;
16
17
class Events implements BehaviourInterface
18
{
19
    protected $mapperName;
20
21
    /**
22
     * @var EventDispatcherInterface
23
     */
24
    protected $events;
25
26
    public function __construct(EventDispatcherInterface $events, string $mapperName)
27
    {
28
        $this->events     = $events;
29
        $this->mapperName = $mapperName;
30
    }
31
32
    public function getName()
33
    {
34
        return 'events';
35
    }
36
37
    public function onNewQuery(Mapper $mapper, Query $query)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

37
    public function onNewQuery(/** @scrutinizer ignore-unused */ Mapper $mapper, Query $query)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $event = new NewMapperQuery($this->mapperName, $query);
40
        $this->events->dispatch($event);
41
42
        return $event->getQuery();
43
    }
44
45
    public function onNewEntity(Mapper $mapper, EntityInterface $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

45
    public function onNewEntity(/** @scrutinizer ignore-unused */ Mapper $mapper, EntityInterface $entity)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        $event = new NewEntity($this->mapperName, $entity);
48
        $this->events->dispatch($event);
49
50
        return $event->getEntity();
51
    }
52
53
    public function onSaving(Mapper $mapper, EntityInterface $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
    public function onSaving(/** @scrutinizer ignore-unused */ Mapper $mapper, EntityInterface $entity)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        $event = new SavingEntity($this->mapperName, $entity);
56
        $this->events->dispatch($event);
57
58
        return $event->getEntity();
59
    }
60
61
    public function onSaved(Mapper $mapper, EntityInterface $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function onSaved(/** @scrutinizer ignore-unused */ Mapper $mapper, EntityInterface $entity)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
        $event = new SavedEntity($this->mapperName, $entity);
64
        $this->events->dispatch($event);
65
66
        return $event->getEntity();
67
    }
68
69
    public function onDeleting(Mapper $mapper, EntityInterface $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
    public function onDeleting(/** @scrutinizer ignore-unused */ Mapper $mapper, EntityInterface $entity)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        $event = new DeletingEntity($this->mapperName, $entity);
72
        $this->events->dispatch($event);
73
74
        return $event->getEntity();
75
    }
76
77
    public function onDeleted(Mapper $mapper, EntityInterface $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

77
    public function onDeleted(/** @scrutinizer ignore-unused */ Mapper $mapper, EntityInterface $entity)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79
        $event = new DeletedEntity($this->mapperName, $entity);
80
        $this->events->dispatch($event);
81
82
        return $event->getEntity();
83
    }
84
}
85