Migrated   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 9 2
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\Delta\Collection;
21
22
use Baleen\Migrations\Exception\Version\Collection\CollectionException;
23
use Baleen\Migrations\Delta\DeltaInterface;
24
25
/**
26
 * Class Migrated
27
 * @author Gabriel Somoza <[email protected]>
28
 */
29
class Migrated extends Collection
30
{
31
    /**
32
     * Returns true if the specified version is valid (can be added) to the collection. Otherwise, it MUST throw
33
     * an exception.
34
     *
35
     * @param DeltaInterface $version
36
     *
37
     * @return bool
38
     *
39
     * @throws CollectionException
40
     */
41 5
    public function validate(DeltaInterface $version)
42
    {
43 5
        if (!$version->isMigrated()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $version->isMigrated() of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
44 1
            throw new CollectionException(
45
                'Invalid version specified: this collection only accepts deltas that are migrated.'
46 1
            );
47
        }
48 4
        return parent::validate($version);
49
    }
50
}
51