Failed Conditions
Push — master ( d49c03...6343d0 )
by Bernhard
05:03
created

RemoveBindingDescriptorFromModuleFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.86%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A execute() 9 9 2
A rollback() 6 6 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 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\Discovery\BindingDescriptor;
15
use Puli\Manager\Api\Module\RootModuleFile;
16
use Puli\Manager\Transaction\AtomicOperation;
17
use Rhumsaa\Uuid\Uuid;
18
19
/**
20
 * Removes a binding descriptor from the root module file.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26 View Code Duplication
class RemoveBindingDescriptorFromModuleFile 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...
27
{
28
    /**
29
     * @var Uuid
30
     */
31
    private $uuid;
32
33
    /**
34
     * @var RootModuleFile
35
     */
36
    private $rootModuleFile;
37
38
    /**
39
     * @var BindingDescriptor
40
     */
41
    private $previousDescriptor;
42
43 7
    public function __construct(Uuid $uuid, RootModuleFile $rootModuleFile)
44
    {
45 7
        $this->uuid = $uuid;
46 7
        $this->rootModuleFile = $rootModuleFile;
47 7
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 7
    public function execute()
53
    {
54 7
        if (!$this->rootModuleFile->hasBindingDescriptor($this->uuid)) {
55
            return;
56
        }
57
58 7
        $this->previousDescriptor = $this->rootModuleFile->getBindingDescriptor($this->uuid);
59 7
        $this->rootModuleFile->removeBindingDescriptor($this->uuid);
60 7
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 2
    public function rollback()
66
    {
67 2
        if ($this->previousDescriptor) {
68 2
            $this->rootModuleFile->addBindingDescriptor($this->previousDescriptor);
69
        }
70 2
    }
71
}
72