Completed
Pull Request — master (#15)
by Gabriel
03:36
created

Version   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 11.24 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 2
cbo 3
dl 10
loc 89
ccs 25
cts 25
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 2
A getId() 0 4 1
A __toString() 0 4 1
A isSameIdentityAs() 0 8 2
A isMigrated() 0 4 1
A setMigrated() 0 4 1
A getMigrateCommand() 0 4 1
A getMigration() 0 4 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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <https://github.com/baleen/migrations>.
18
 */
19
20
namespace Baleen\Migrations\Version;
21
22
use Baleen\Migrations\Migration\Command\MigrateCommand;
23
use Baleen\Migrations\Migration\MigrationInterface;
24
use Baleen\Migrations\Migration\OptionsInterface;
25
use Baleen\Migrations\Shared\EntityInterface;
26
27
/**
28
 * {@inheritDoc}
29
 *
30
 * @author Gabriel Somoza <[email protected]>
31
 */
32
final class Version implements VersionInterface
33
{
34
    /** @var VersionId */
35
    private $id;
36
37
    /** @var bool */
38
    private $migrated;
39
40
    /** @var MigrationInterface */
41
    private $migration;
42
43
    /**
44
     * @param MigrationInterface $migration
45
     * @param bool $migrated
46
     * @param null|VersionId $id Optionally force the ID to be something specific.
47
     *
48
     * @throws \Baleen\Migrations\Exception\InvalidArgumentException
49
     */
50 121 View Code Duplication
    public function __construct(MigrationInterface $migration, $migrated, VersionId $id = null)
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...
51
    {
52 121
        if (null === $id) {
53 1
            $id = VersionId::fromMigration($migration);
54 1
        }
55 121
        $this->id = $id;
56
57 121
        $this->migration = $migration;
58 121
        $this->migrated = (bool) $migrated;
59 121
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64 154
    public function getId()
65
    {
66 154
        return $this->id;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72 49
    public function __toString()
73
    {
74 49
        return $this->getId()->toString();
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80 9
    public function isSameIdentityAs(EntityInterface $entity)
81
    {
82 9
        if (!$entity instanceof VersionInterface) {
83 1
            return false;
84
        }
85
86 9
        return $this->getId()->isSameValueAs($entity->getId());
87
    }
88
89
    /**
90
     * @inheritDoc
91
     */
92 45
    public function isMigrated()
93
    {
94 45
        return $this->migrated;
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100 17
    public function setMigrated($migrated)
101
    {
102 17
        $this->migrated = $migrated;
103 17
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 14
    public function getMigrateCommand(OptionsInterface $options)
109
    {
110 14
        return new MigrateCommand($this->getMigration(), $options);
111
    }
112
113
    /**
114
     * @inheritdoc
115
     */
116 45
    public function getMigration()
117
    {
118 45
        return $this->migration;
119
    }
120
}
121