Passed
Push — dev ( e02ab0...798ae0 )
by James Ekow Abaka
02:10
created

Migrate::setRollbackCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "Migrate.php" doesn't match the expected filename "migrate.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
4
 * The MIT License
0 ignored issues
show
Coding Style introduced by
First line of comment not aligned correctly; expected 4 spaces but found 1
Loading history...
5
 *
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
6
 * Copyright 2014 James Ekow Abaka Ainooson
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
7
 *
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
9
 * of this software and associated documentation files (the "Software"), to deal
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
10
 * in the Software without restriction, including without limitation the rights
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
12
 * copies of the Software, and to permit persons to whom the Software is
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
13
 * furnished to do so, subject to the following conditions:
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
14
 *
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
15
 * The above copyright notice and this permission notice shall be included in
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
16
 * all copies or substantial portions of the Software.
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
17
 *
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
24
 * THE SOFTWARE.
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 4 spaces but found 1
Loading history...
25
 */
0 ignored issues
show
Coding Style introduced by
Last line of comment aligned incorrectly; expected 0 spaces but found 1
Loading history...
26
27
namespace yentu\commands;
28
29
use clearice\io\Io;
30
use yentu\database\Begin;
31
use yentu\database\DatabaseItem;
32
use yentu\ChangeLogger;
33
use yentu\database\ForeignKey;
34
use yentu\Reversible;
35
36
/**
37
 * The migrate command for the yentu database migration system. This class is
38
 * responsible for creating and updating items 
39
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
40
class Migrate extends Command implements Reversible
41
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class Migrate
Loading history...
42
43
    const FILTER_UNRUN = 'unrun';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44
    const FILTER_LAST_SESSION = 'lastSession';
45
46
    private $driver;
0 ignored issues
show
Coding Style introduced by
Private member variable "driver" must contain a leading underscore
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "driver" must be prefixed with an underscore
Loading history...
47
    private $dryDriver;
0 ignored issues
show
Coding Style introduced by
Private member variable "dryDriver" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "dryDriver" must be prefixed with an underscore
Loading history...
48
    private $defaultSchema = false;
0 ignored issues
show
Coding Style introduced by
Private member variable "defaultSchema" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "defaultSchema" must be prefixed with an underscore
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
49
    private $lastSession;
0 ignored issues
show
Coding Style introduced by
Private member variable "lastSession" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "lastSession" must be prefixed with an underscore
Loading history...
50
    private $currentPath;
0 ignored issues
show
Coding Style introduced by
Private member variable "currentPath" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "currentPath" must be prefixed with an underscore
Loading history...
51
    private $rollbackCommand;
0 ignored issues
show
Coding Style introduced by
Private member variable "rollbackCommand" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
Private member variable "rollbackCommand" must be prefixed with an underscore
Loading history...
52
53
54
    public function setupOptions($options, &$filter)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
55
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
56
        if (isset($options['no-foreign-keys'])) {
57
            $this->io->output("Ignoring all foreign key constraints ...\n");
0 ignored issues
show
Bug introduced by
The method output() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            $this->io->/** @scrutinizer ignore-call */ 
58
                       output("Ignoring all foreign key constraints ...\n");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
            $this->driver->skip('ForeignKey');
59
        }
60
61
        if (isset($options['only-foreign-keys'])) {
62
            $this->io->output("Applying only foreign keys ...\n");
63
            $this->lastSession = $this->driver->getLastSession();
64
            $this->driver->allowOnly('ForeignKey');
65
            $filter = self::FILTER_LAST_SESSION;
66
        }
67
68
        if (isset($options['force-foreign-keys'])) {
69
            $this->io->output("Applying only foreign keys and skipping on errors ...\n");
70
            $this->lastSession = $this->driver->getLastSession();
71
            $this->driver->setSkipOnErrors($options['force-foreign-keys']);
72
            $this->driver->allowOnly('ForeignKey');
73
            $filter = self::FILTER_LAST_SESSION;
74
        }
75
76
        if (isset($options['default-ondelete-action'])) {
77
            ForeignKey::$defaultOnDelete = $options['default-ondelete-action'];
78
        }
79
80
        if (isset($options['default-onupdate-action'])) {
81
            ForeignKey::$defaultOnUpdate = $options['default-onupdate-action'];
82
        }
83
84
        $this->setDefaultSchema($options);
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
86
87
    private function setDefaultSchema($options)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::setDefaultSchema" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
88
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
89
        global $defaultSchema;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
90
        if (isset($options['default-schema'])) {
91
            $this->driver->setDefaultSchema($options['default-schema']);
92
            $this->defaultSchema = $options['default-schema'];
93
            $defaultSchema = $this->defaultSchema;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
94
        }
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
96
97
    private function announceMigration($migrations, $path)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::announceMigration" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
98
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
99
        $size = count($migrations);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
100
        $defaultSchema = null;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
101
        if ($size > 0) {
102
            if (isset($path['default-schema'])) {
103
                $defaultSchema = $path['default-schema'];
104
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
105
            $this->io->output("Running $size migration(s) from '{$path['home']}'");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $size instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $path instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
106
            if ($defaultSchema != '') {
0 ignored issues
show
Coding Style introduced by
Operator != prohibited; use !== instead
Loading history...
107
                $this->io->output(" with '$defaultSchema' as the default schema.\n");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $defaultSchema instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
108
            }
109
        } else {
110
            $this->io->output("No migrations to run from '{$path['home']}'\n");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $path instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
111
        }
112
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
113
114
    public function getBegin()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
115
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
116
        return new Begin($this->defaultSchema);
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
118
119
    private static function fillOptions(&$options)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::fillOptions" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
120
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
121
        if (!isset($options['dump-queries'])) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
122
            $options['dump-queries'] = false;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
123
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
124
        if (!isset($options['dry'])) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
125
            $options['dry'] = false;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
126
        }
127
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
128
129
    public function run($options = array())
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$options" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$options"; expected 0 but found 1
Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
130
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
131
        global $migrateCommand;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
132
        global $migrateVariables;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
133
134
        self::fillOptions($options);
135
136
        $migrateCommand = $this;
137
138
        if ($options['dump-queries'] !== true) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
139
            $this->yentu->greet();
140
        }
141
142
        $this->driver = ChangeLogger::wrap($this->manipulatorFactory->createManipulator(), $this->yentu, $this->io);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 116 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Bug introduced by
The method createManipulator() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

142
        $this->driver = ChangeLogger::wrap($this->manipulatorFactory->/** @scrutinizer ignore-call */ createManipulator(), $this->yentu, $this->io);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
It seems like $this->io can also be of type null; however, parameter $io of yentu\ChangeLogger::wrap() does only seem to accept clearice\io\Io, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

142
        $this->driver = ChangeLogger::wrap($this->manipulatorFactory->createManipulator(), $this->yentu, /** @scrutinizer ignore-type */ $this->io);
Loading history...
143
        $this->driver->setDumpQueriesOnly($options['dump-queries']);
144
        $this->driver->setDryRun($options['dry']);
145
146
        $totalOperations = 0;
147
148
        $filter = self::FILTER_UNRUN;
149
        $this->setupOptions($options, $filter);
150
        DatabaseItem::setDriver($this->driver);
151
152
        \yentu\Timer::start();
153
        $migrationPaths = $this->yentu->getMigrationPaths();
154
        //$migrationsToBeRun = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Coding Style introduced by
No space found before comment text; expected "// $migrationsToBeRun = [];" but found "//$migrationsToBeRun = [];"
Loading history...
155
        foreach ($migrationPaths as $path) {
156
            $this->setDefaultSchema($path);
157
            $migrateVariables = $path['variables'] ?? [];
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
158
            $migrations = $this->filter($this->yentu->getMigrations($path['home']), $filter);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
159
            $this->announceMigration($migrations, $path);
160
            $this->currentPath = $path;
161
162
            foreach ($migrations as $migration) {
163
                $this->countOperations("{$path['home']}/{$migration['file']}");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $path instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $migration instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
164
                $this->driver->setVersion($migration['timestamp']);
165
                $this->driver->setMigration($migration['migration']);
166
                $this->io->output("\nApplying '{$migration['migration']}' migration\n");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $migration instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
167
                require "{$path['home']}/{$migration['file']}";
0 ignored issues
show
Coding Style introduced by
File is being conditionally included; use "include" instead
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $path instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $migration instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
168
                DatabaseItem::purge();
169
                $this->io->output("\n");
170
                $totalOperations += $this->driver->resetOperations();
171
            }
172
        }
173
174
        if ($this->driver->getChanges()) {
175
            $elapsed = \yentu\Timer::stop();
176
            $this->io->output("\nMigration took " . \yentu\Timer::pretty($elapsed) . "\n");
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
177
            $this->io->output($this->driver->getChanges() . " operations performed\n");
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
178
            $this->io->output($totalOperations - $this->driver->getChanges() . " operations skipped\n");
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
179
        }
180
181
        $this->driver->disconnect();
0 ignored issues
show
Bug introduced by
The method disconnect() does not exist on yentu\ChangeLogger. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

181
        $this->driver->/** @scrutinizer ignore-call */ 
182
                       disconnect();
Loading history...
182
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
183
184
    private function filter($migrations, $type = self::FILTER_UNRUN)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::filter" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$type" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$type"; expected 0 but found 1
Loading history...
185
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
186
        $filterMethod = "{$type}Filter";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $type instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
187
        return $this->$filterMethod($migrations);
188
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
189
190
    private function countOperations($migrationFile)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::countOperations" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
191
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
192
        if ($this->dryDriver === null) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
193
            $this->dryDriver = clone $this->driver;
194
            $this->dryDriver->setDryRun(true);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
195
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
196
        $this->io->pushOutputLevel(Io::OUTPUT_LEVEL_0);
197
        DatabaseItem::setDriver($this->dryDriver);
198
        require "$migrationFile";
0 ignored issues
show
Coding Style introduced by
File is being conditionally included; use "include" instead
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $migrationFile instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
199
        DatabaseItem::purge();
200
        DatabaseItem::setDriver($this->driver);
201
        $this->io->popOutputLevel();
202
        $this->driver->setExpectedOperations($this->dryDriver->resetOperations());
203
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
204
205
    public function getCurrentPath()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
206
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
207
        return $this->currentPath;
208
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
209
210
    private function unrunFilter($input)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::unrunFilter" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
211
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
212
        $output = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
213
        foreach ($input as $migration) {
214
            $run = $this->driver->query(
215
                "SELECT count(*) as number_run FROM yentu_history WHERE migration = ? and version = ? and default_schema = ?", 
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SELECT count(*) as numbe... and default_schema = ? does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
216
                array($migration['migration'], $migration['timestamp'], (string) $this->defaultSchema)
0 ignored issues
show
Coding Style introduced by
Arrays with multiple values should not be declared on a single line.
Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
Coding Style introduced by
A cast statement should not be followed as per the coding-style.
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 102 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
217
            );
218
219
            if ($run[0]['number_run'] == 0) {
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
220
                $output[] = $migration;
221
            }
222
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
223
        return $output;
224
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
225
226
    private function lastSessionFilter($input)
0 ignored issues
show
Coding Style introduced by
Private method name "Migrate::lastSessionFilter" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
227
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
228
        $versions = $this->driver->getSessionVersions($this->lastSession);
229
        $output = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
230
        foreach ($input as $migration) {
231
            if (array_search($migration['timestamp'], $versions) !== false) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
232
                $output[] = $migration;
233
            }
234
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
235
        return $output;
236
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
237
238
    public function getChanges()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
239
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
240
        return $this->driver->getChanges();
241
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
242
243
    public function setRollbackCommand(Rollback $rollbackCommand)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
244
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
245
        $this->rollbackCommand = $rollbackCommand;
246
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
247
248
    public function reverse()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
249
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
250
        if ($this->driver === null) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
251
            return;
252
        }
253
254
        $this->io->output("Attempting to reverse all changes ... ");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Attempting to reverse all changes ... does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
255
        if ($this->getChanges() > 0) {
256
            $this->io->pushOutputLevel(0);
257
            $this->rollbackCommand->run(array());
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
258
            $this->io->popOutputLevel();
259
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
260
        $this->io->output("OK\n");
261
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
262
263
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
264