Completed
Push — master ( 808f8c...952fde )
by Vladimir
11s
created

FileDeletionSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 27
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A onFileDeletion() 5 5 1
A getSubscribedEvents() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\EventSubscriber;
9
10
use allejo\stakx\Compiler;
11
use allejo\stakx\Core\StakxLogger;
12
use allejo\stakx\Filesystem\FilesystemLoader as fs;
13
use Kwf\FileWatcher\Event\Delete as DeleteEvent;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
16 View Code Duplication
class FileDeletionSubscriber implements EventSubscriberInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    private $compiler;
19
    private $logger;
20
21
    public function __construct(Compiler $compiler, StakxLogger $logger)
22
    {
23
        $this->compiler = $compiler;
24
        $this->logger = $logger;
25
    }
26
27
    public function onFileDeletion(DeleteEvent $event)
28
    {
29
        $relFilePath = fs::getRelativePath($event->filename);
30
        $this->logger->writeln(sprintf('File deletion detected: %s', $relFilePath));
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public static function getSubscribedEvents()
37
    {
38
        return [
39
            DeleteEvent::NAME => 'onFileDeletion'
40
        ];
41
    }
42
}
43