MessageRemoveSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
c 0
b 0
f 0
dl 0
loc 22
rs 10
ccs 9
cts 11
cp 0.8182

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 3 1
A postRemove() 0 7 3
A __construct() 0 2 1
1
<?php
2
3
namespace App\Doctrine;
4
5
use App\Entity\Message;
6
use App\Entity\MessageAttachment;
7
use App\Filesystem\MessageFilesystem;
8
use Doctrine\Common\EventSubscriber;
9
use Doctrine\ORM\Event\LifecycleEventArgs;
10
use Doctrine\ORM\Events;
11
12
/**
13
 * Listens to Message/MessageAttachment removals in order to remove files and directories from the filesystem.
14
 */
15
class MessageRemoveSubscriber implements EventSubscriber {
16
17
    public function __construct(private MessageFilesystem $filesystem)
18
    {
19 25
    }
20 25
21 25
    public function postRemove(LifecycleEventArgs $eventArgs) {
22
        $entity = $eventArgs->getEntity();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\Event\LifecycleEventArgs::getEntity() has been deprecated: 2.13. Use {@see getObject} instead. ( Ignorable by Annotation )

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

22
        $entity = /** @scrutinizer ignore-deprecated */ $eventArgs->getEntity();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
23 6
24 6
        if($entity instanceof Message) {
25
            $this->filesystem->removeMessageDirectoy($entity);
26 6
        } else if($entity instanceof MessageAttachment) {
27
            $this->filesystem->removeMessageAttachment($entity);
28 6
        }
29
    }
30
31 6
    /**
32
     * @inheritDoc
33
     */
34
    public function getSubscribedEvents(): array {
35
        return [
36 25
            Events::postRemove
37
        ];
38
    }
39
}