Completed
Push — master ( 771e5d...491b8d )
by Jeff
02:21
created

DKIMDomainSubscriber   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A postUpdate() 0 3 1
A postPersist() 0 3 1
A doUpdate() 0 6 2
A postRemove() 0 3 1
A __construct() 0 3 1
A getSubscribedEvents() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Subscriber;
12
13
use App\Entity\Domain;
14
use App\Service\Config\Manager;
15
use Doctrine\Common\EventSubscriber;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Events;
18
19
class DKIMDomainSubscriber implements EventSubscriber
20
{
21
    private $manager;
22
23
    public function __construct(Manager $manager)
24
    {
25
        $this->manager = $manager;
26
    }
27
28
    public function getSubscribedEvents(): array
29
    {
30
        return [
31
            Events::postUpdate,
32
            Events::postPersist,
33
            Events::postRemove,
34
        ];
35
    }
36
37
    public function postUpdate(LifecycleEventArgs $args): void
38
    {
39
        $this->doUpdate($args);
40
    }
41
42
    public function postPersist(LifecycleEventArgs $args): void
43
    {
44
        $this->doUpdate($args);
45
    }
46
47
    public function postRemove(LifecycleEventArgs $args): void
48
    {
49
        $this->doUpdate($args);
50
    }
51
52
    private function doUpdate(LifecycleEventArgs $args): void
53
    {
54
        $entity = $args->getObject();
55
56
        if ($entity instanceof Domain) {
57
            $this->manager->refresh();
58
        }
59
    }
60
}
61