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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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