DisableBindingUuid   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 44
loc 44
wmc 5
lcom 1
cbo 1
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 7 7 2
A rollback() 6 6 2
A __construct() 5 5 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
 * This file is part of the puli/manager package.
5
 *
6
 * (c) Bernhard Schussek <[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 Puli\Manager\Discovery\Binding;
13
14
use Puli\Manager\Api\Module\InstallInfo;
15
use Puli\Manager\Transaction\AtomicOperation;
16
use Rhumsaa\Uuid\Uuid;
17
18
/**
19
 * Disables a binding descriptor for a given install info.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 */
25 View Code Duplication
class DisableBindingUuid implements AtomicOperation
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...
26
{
27
    /**
28
     * @var Uuid
29
     */
30
    private $uuid;
31
32
    /**
33
     * @var InstallInfo
34
     */
35
    private $installInfo;
36
37
    /**
38
     * @var bool
39
     */
40
    private $wasDisabled = true;
41
42 3
    public function __construct(Uuid $uuid, InstallInfo $installInfo)
43
    {
44 3
        $this->uuid = $uuid;
45 3
        $this->installInfo = $installInfo;
46 3
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 3
    public function execute()
52
    {
53 3
        if (!$this->installInfo->hasDisabledBindingUuid($this->uuid)) {
54 3
            $this->wasDisabled = false;
55 3
            $this->installInfo->addDisabledBindingUuid($this->uuid);
56
        }
57 3
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function rollback()
63
    {
64 2
        if (!$this->wasDisabled) {
65 2
            $this->installInfo->removeDisabledBindingUuid($this->uuid);
66
        }
67 2
    }
68
}
69