VcsSubscriber   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 62.75 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 27.27%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 32
loc 51
ccs 6
cts 22
cp 0.2727
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 7 1
A onVcsPreCheckout() 16 16 2
A onVcsPreExport() 16 16 2

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
 * This file is part of the Conveyor package.
5
 *
6
 * (c) Jeroen Fiege <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webcreate\Conveyor\Subscriber;
13
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Webcreate\Conveyor\IO\IOInterface;
16
use Webcreate\Vcs\Common\Event\Data\CheckoutEventData;
17
use Webcreate\Vcs\Common\Event\Data\ExportEventData;
18
use Webcreate\Vcs\Common\Event\VcsEvent;
19
use Webcreate\Vcs\Common\VcsEvents;
20
21
class VcsSubscriber implements EventSubscriberInterface
22
{
23
    protected $io;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $io. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
24
25 1
    public function __construct(IOInterface $io)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $io. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
26
    {
27 1
        $this->io = $io;
28 1
    }
29
30 1
    public static function getSubscribedEvents()
31
    {
32
        return array(
33 1
            VcsEvents::PRE_CHECKOUT => array('onVcsPreCheckout'),
34 1
            VcsEvents::PRE_EXPORT => array('onVcsPreExport'),
35
        );
36
    }
37
38 View Code Duplication
    public function onVcsPreCheckout(VcsEvent $event)
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40
        if (false === $this->io->isVerbose()) return;
0 ignored issues
show
Coding Style introduced by
Please always use braces to surround the code block of IF statements.
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
41
42
        /** @var CheckoutEventData $data */
43
        $data = $event->getData();
44
45
        $this->io->write(
46
            sprintf(
47
                'Checking out <comment>%s</comment> to <comment>%s</comment>...'
48
                ,
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
49
                $data->getHead()->getName(),
50
                $data->getDestination()
51
            )
52
        );
53
    }
54
55 View Code Duplication
    public function onVcsPreExport(VcsEvent $event)
0 ignored issues
show
Duplication introduced by
This method 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...
56
    {
57
        if (false === $this->io->isVerbose()) return;
0 ignored issues
show
Coding Style introduced by
Please always use braces to surround the code block of IF statements.
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
58
59
        /** @var ExportEventData $data */
60
        $data = $event->getData();
61
62
        $this->io->write(
63
            sprintf(
64
                'Exporting <comment>%s</comment> to <comment>%s</comment>...'
65
                ,
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
66
                $data->getHead()->getName(),
67
                $data->getDestination()
68
            )
69
        );
70
    }
71
}
72