Completed
Push — master ( 2c6719...58280f )
by Gaetano
11:02
created

MigrateTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 98
Duplicated Lines 85.71 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 84
loc 98
wmc 10
lcom 2
cbo 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B testExecuteGoodDSL() 30 30 2
B testExecuteBadDSL() 30 30 2
A goodDSLProvider() 12 12 3
A badDSLProvider() 12 12 3

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
include_once(__DIR__.'/CommandTest.php');
4
5
use Symfony\Component\Console\Input\ArrayInput;
6
7
/**
8
 * Tests the 'migrate' as well as the 'migration' command
9
 */
10
class MigrateTest extends CommandTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    /**
13
     * @param string $filePath
14
     * @dataProvider goodDSLProvider
15
     */
16 View Code Duplication
    public function testExecuteGoodDSL($filePath = '')
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...
17
    {
18
        if ($filePath == '') {
19
            $this->markTestSkipped();
20
            return;
21
        }
22
23
        // Make user migration is not in the db: delete it, ignoring errors
24
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
25
        $exitCode = $this->app->run($input, $this->output);
0 ignored issues
show
Unused Code introduced by
$exitCode is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
        $output = $this->output->fetch();
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
28
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => $filePath, '--add' => true, '-n' => true));
29
        $exitCode = $this->app->run($input, $this->output);
30
        $output = $this->output->fetch();
31
        $this->assertSame(0, $exitCode);
32
        $this->assertRegexp('?Added migration?', $output);
33
34
        $input = new ArrayInput(array('command' => 'kaliop:migration:migrate', '--path' => array($filePath), '-n' => true));
35
        $exitCode = $this->app->run($input, $this->output);
36
        $output = $this->output->fetch();
37
        $this->assertSame(0, $exitCode);
38
        // check that there are no notes after adding the migration
39
        $this->assertRegexp('?\| ' . basename($filePath) . ' +\| +\|?', $output);
40
41
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
42
        $exitCode = $this->app->run($input, $this->output);
43
        $output = $this->output->fetch();
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
        $this->assertSame(0, $exitCode);
45
    }
46
47
    /**
48
     * @param string $filePath
49
     * @dataProvider badDSLProvider
50
     */
51 View Code Duplication
    public function testExecuteBadDSL($filePath = '')
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...
52
    {
53
        if ($filePath == '') {
54
            $this->markTestSkipped();
55
            return;
56
        }
57
58
        // Make user migration is not in the db: delete it, ignoring errors
59
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
60
        $exitCode = $this->app->run($input, $this->output);
0 ignored issues
show
Unused Code introduced by
$exitCode is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
        $output = $this->output->fetch();
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
63
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => $filePath, '--add' => true, '-n' => true));
64
        $exitCode = $this->app->run($input, $this->output);
65
        $output = $this->output->fetch();
66
        $this->assertSame(0, $exitCode);
67
        $this->assertRegexp('?Added migration?', $output);
68
69
        $input = new ArrayInput(array('command' => 'kaliop:migration:migrate', '--path' => array($filePath), '-n' => true));
70
        $exitCode = $this->app->run($input, $this->output);
71
        $output = $this->output->fetch();
72
        $this->assertSame(0, $exitCode);
73
        // check that there are no notes after adding the migration
74
        $this->assertRegexp('?Skipping ' . basename($filePath) . '?', $output);
75
76
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
77
        $exitCode = $this->app->run($input, $this->output);
78
        $output = $this->output->fetch();
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
        $this->assertSame(0, $exitCode);
80
    }
81
82 View Code Duplication
    public function goodDSLProvider()
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...
83
    {
84
        $dslDir = $this->dslDir.'/good';
85
        $out = array();
86
        foreach(scandir($dslDir) as $fileName) {
87
            $filePath = $dslDir . '/' . $fileName;
88
            if (is_file($filePath)) {
89
                $out[] = array($filePath);
90
            }
91
        }
92
        return $out;
93
    }
94
95 View Code Duplication
    public function badDSLProvider()
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...
96
    {
97
        $dslDir = $this->dslDir.'/bad';
98
        $out = array();
99
        foreach(scandir($dslDir) as $fileName) {
100
            $filePath = $dslDir . '/' . $fileName;
101
            if (is_file($filePath)) {
102
                $out[] = array($filePath);
103
            }
104
        }
105
        return $out;
106
    }
107
}
108