Failed Conditions
Pull Request — master (#56)
by Bernhard
11:07
created

RemoveBindingDescriptorFromModuleFile::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
ccs 0
cts 8
cp 0
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
crap 6
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
    public function __construct(Uuid $uuid, RootModuleFile $rootModuleFile)
44
    {
45
        $this->uuid = $uuid;
46
        $this->rootModuleFile = $rootModuleFile;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function execute()
53
    {
54
        if (!$this->rootModuleFile->hasBindingDescriptor($this->uuid)) {
0 ignored issues
show
Documentation introduced by
$this->uuid is of type object<Rhumsaa\Uuid\Uuid>, but the function expects a object<Puli\Discovery\Api\Binding\Binding>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
            return;
56
        }
57
58
        $this->previousDescriptor = $this->rootModuleFile->getBindingDescriptor($this->uuid);
0 ignored issues
show
Documentation introduced by
$this->uuid is of type object<Rhumsaa\Uuid\Uuid>, but the function expects a object<Puli\Discovery\Api\Binding\Binding>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
        $this->rootModuleFile->removeBindingDescriptor($this->uuid);
0 ignored issues
show
Documentation introduced by
$this->uuid is of type object<Rhumsaa\Uuid\Uuid>, but the function expects a object<Puli\Discovery\Api\Binding\Binding>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function rollback()
66
    {
67
        if ($this->previousDescriptor) {
68
            $this->rootModuleFile->addBindingDescriptor($this->previousDescriptor);
69
        }
70
    }
71
}
72