Completed
Push — dev ( 798ae0...4b619a )
by James Ekow Abaka
04:30
created

Yentu::setDatabaseManipuatorFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 "Yentu.php" doesn't match the expected filename "yentu.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 2015 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;
28
use clearice\io\Io;
29
use ntentan\config\Config;
30
use yentu\factories\DatabaseManipulatorFactory;
31
32
33
/**
34
 * Utility class for yentu related functions.
35
 */
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...
36
class Yentu
37
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class Yentu
Loading history...
38
39
    /**
40
     * The current home path for yentu.
41
     * The home path represents the location of migrations and the configurations used for the yentu session.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 109 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...
42
     *
43
     * @var string
44
     */
45
    private $home;
0 ignored issues
show
Coding Style introduced by
Private member variable "home" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "home" must be prefixed with an underscore
Loading history...
46
47
    /**
48
     * An instance of the clearice Io class
49
     * @var Io
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
50
     */
51
    private $io;
0 ignored issues
show
Coding Style introduced by
Private member variable "io" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "io" must be prefixed with an underscore
Loading history...
52
    private $databaseManipulatorFactory;
0 ignored issues
show
Coding Style introduced by
Private member variable "databaseManipulatorFactory" 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 "databaseManipulatorFactory" must be prefixed with an underscore
Loading history...
53
    private $config;
0 ignored issues
show
Coding Style introduced by
Private member variable "config" 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 "config" must be prefixed with an underscore
Loading history...
54
55
    /**
56
     * Current version of yentu.
57
     * @var string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
58
     */
59
    const VERSION = 'v0.3.0';
60
61 41
    public function __construct(Io $io, DatabaseManipulatorFactory $databaseManipulatorFactory)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
62
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
63 41
        $this->databaseManipulatorFactory = $databaseManipulatorFactory;
64 41
        $this->io = $io;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 25 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...
65 41
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
66
67
    /**
68
     * Set the current home of yentu.
69
     * The home of yentu contains is a directory which contains the yentu 
70
     * configurations and migrations. Configurations are stored in the config
71
     * sub directory and the migrations are stored in the migrations sub
72
     * directory. 
73
     * @param string $home
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
74
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
75 41
    public function setDefaultHome($home)
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $home
Loading history...
76
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
77 41
        $this->home = $home;
78 41
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
79
80
    /**
81
     * Inject a configuration object
82
     * @param Config $config
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
83
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
84 41
    public function setConfig(Config $config)
85
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
86 41
        $this->config = $config;
87 41
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
88
89
    public function getConfig() : Config
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
90
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
91
        return $this->config;
92
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
93
94
    /**
95
     * Returns a path relative to the current yentu home.
96
     * @param string $path
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
97
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
98
     */
99 41
    public function getPath($path)
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $path
Loading history...
100
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
101 41
        return $this->home . "/$path";
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
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...
102
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
103
104
    /**
105
     * Returns an array of all migrations that have been run on the database.
106
     * The information returned includes the timestamp, the name of the migration
107
     * and the default schema on which it was run.
108
     *
109
     * @return array
110
     * @throws exceptions\DatabaseManipulatorException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
111
     */
112
    public function getExecutedMigrations()
113
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
114
        $db = $this->databaseManipulatorFactory->createManipulator();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
115
        $runMigrations = $db->query("SELECT DISTINCT version, migration, default_schema FROM yentu_history ORDER BY version");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SELECT DISTINCT version,...istory ORDER BY version 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 126 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...
116
        $migrations = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
117
        foreach ($runMigrations as $migration) {
118
            $migrations[$migration['version']] = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
119
                'timestamp' => $migration['version'],
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 50 spaces, but found 16.
Loading history...
120
                'migration' => $migration['migration'],
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 50 spaces, but found 16.
Loading history...
121
                'default_schema' => $migration['default_schema']
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 50 spaces, but found 16.
Loading history...
122
            );
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 49 space(s), but found 12.
Loading history...
123
        }
124
125
        return $migrations;
126
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
127
128
    /**
129
     * Returns an array of all migrations, in all configured migrations directories.
130
     *
131
     * @return array
132
     */
133
    public function getAllMigrations()
134
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
135
        $migrations = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
136
        foreach ($this->getMigrationPaths() as $migration) {
137
            $migrations = $migrations + $this->getMigrationsFromPath($migration['home']);
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
138
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
139
        return $migrations;
140
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
141
142 10
    public function getMigrationPaths()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
143
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
144 10
        $variables = $this->config->get('variables', []);
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...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
145 10
        $otherMigrations = $this->config->get('other_migrations', []);
0 ignored issues
show
Coding Style introduced by
Short array syntax is not allowed
Loading history...
146
147 10
        return array_merge(
148
            array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
149
                array(
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 13 spaces, but found 16.
Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
150 10
                    'home' => $this->getPath('migrations'),
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 17 spaces, but found 20.
Loading history...
151 10
                    'variables' => $variables
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 17 spaces, but found 20.
Loading history...
152
                )
0 ignored issues
show
Coding Style introduced by
There should be a trailing comma after the last value of an array declaration.
Loading history...
153 10
            ), $otherMigrations
154
        );
155
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
156
157
    /**
158
     * Return an array of all migrations from a given migration path
159
     * 
160
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
161
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
162
     */
163 10
    public function getMigrationsFromPath($path)
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $path
Loading history...
164
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
165 10
        if (!file_exists($path))
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
166
            return [];
0 ignored issues
show
Coding Style introduced by
Short array syntax is not allowed
Loading history...
167 10
        $migrationFiles = scandir($path, 0);
168 10
        $migrations = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
169 10
        foreach ($migrationFiles as $migration) {
170 10
            $details = $this->getMigrationDetails($migration);
171 10
            if ($details === false)
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
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...
172 10
                continue;
173 10
            $migrations[$details['timestamp']] = $details;
174 10
            unset($migrations[$details['timestamp']][0]);
175 10
            unset($migrations[$details['timestamp']][1]);
176 10
            unset($migrations[$details['timestamp']][2]);
177
        }
178
179 10
        return $migrations;
180
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
181
182
    /**
183
     * Return the details of a migration extracted from the file name. This method uses a regular expression to extract
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 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...
184
     * the timestamp and migration name from the migration script.
185
     * 
186
     * @param string $migration
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
187
     * @return array|bool
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Expected "array|boolean" but found "array|bool" for function return type
Loading history...
188
     */
189 10
    private function getMigrationDetails($migration)
0 ignored issues
show
Coding Style introduced by
Private method name "Yentu::getMigrationDetails" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Type hint "string" missing for $migration
Loading history...
190
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
191 10
        if (preg_match("/^(?<timestamp>[0-9]{14})\_(?<migration>[a-z][a-z0-9\_]*)\.php$/", $migration, $details)) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /^(?<timestamp>[0-9]{14}...a-z][a-z0-9\_]*)\.php$/ 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 115 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...
192 10
            $details['file'] = $migration;
193
        } else {
194 10
            $details = 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...
195
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
196 10
        return $details;
197
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
198
199
    /**
200
     * Announce a migration based on the command and the arguments called for the migration.
201
     * 
202
     * @param string $command The action being performed
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
203
     * @param string $itemType The type of item
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 1 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
204
     * @param array $arguments The arguments of the 
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
205
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
206 10
    public function announce($command, $itemType, $arguments)
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $command
Loading history...
Coding Style introduced by
Type hint "string" missing for $itemType
Loading history...
introduced by
Type hint "array" missing for $arguments
Loading history...
207
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
208 10
        $this->io->output(
209 10
            "\n  - " . ucfirst("{$command}ing ") .
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $command 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...
210 10
            preg_replace("/([a-z])([A-Z])/", "$1 $2", $itemType) . " " .
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /([a-z])([A-Z])/ 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 Comprehensibility introduced by
The string literal $1 $2 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
Concat operator must not be surrounded by spaces
Loading history...
Coding Style Comprehensibility introduced by
The string literal 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...
211 10
            $this->getEventDescription($command, Parameters::wrap($arguments)), Io::OUTPUT_LEVEL_2
212
        );
213 10
        $this->io->output(".");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal . 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...
214 10
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
215
216
    /**
217
     * Convert the arguments of a migration event to a string description.
218
     * 
219
     * @param string $command
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
220
     * @param array $arguments
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
221
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
222
     */
223 10
    private function getEventDescription($command, $arguments)
0 ignored issues
show
Coding Style introduced by
Private method name "Yentu::getEventDescription" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Type hint "string" missing for $command
Loading history...
introduced by
Type hint "array" missing for $arguments
Loading history...
224
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
225 10
        $dir = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
226 10
        $destination = '';
227 10
        $arguments = Parameters::wrap($arguments, ['name' => null]);
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 is not allowed
Loading history...
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...
228
229 10
        if ($command == 'add') {
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
230 10
            $dir = 'to';
231 6
        } else if ($command == 'drop') {
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
232
            $dir = 'from';
233
        }
234
235 10
        if (isset($arguments['table']) && isset($arguments['schema'])) {
236
            $destination = "table " .
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style Comprehensibility introduced by
The string literal table 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
Concat operator must not be surrounded by spaces
Loading history...
237 10
                ($arguments['schema'] != '' ? "{$arguments['schema']}." : '' ) .
0 ignored issues
show
Coding Style introduced by
Operator != prohibited; use !== instead
Loading history...
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $arguments 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 introduced by
Concat operator must not be surrounded by spaces
Loading history...
238 10
                "{$arguments['table']}'";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $arguments 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...
239 10
        } elseif (isset($arguments['schema']) && !isset($arguments['table'])) {
0 ignored issues
show
Coding Style introduced by
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
240 10
            $destination = "schema '{$arguments['schema']}'";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $arguments 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...
241
        }
242
243 10
        if (is_string($arguments)) {
244 1
            return $arguments;
245
        }
246
247 10
        if (isset($arguments['column'])) {
248 10
            $item = $arguments['column'];
249
        } else {
250 10
            $item = $arguments['name'];
251
        }
252
253 10
        return "'$item' $dir $destination";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $item 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 $dir 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 $destination 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...
254
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
255
256
    /**
257
     * Reverses a command which is reversible.
258
     * 
259
     * @param \yentu\Reversible $command
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
260
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
261
    public function reverseCommand($command)
0 ignored issues
show
introduced by
Type hint "\yentu\Reversible" missing for $command
Loading history...
262
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
263
        if ($command instanceof \yentu\Reversible) {
0 ignored issues
show
introduced by
$command is always a sub-type of yentu\Reversible.
Loading history...
264
            $command->reverse();
265
        }
266
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
267
    
268
    /**
269
     * Display the greeting for the CLI user interface.
270
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
271 41
    public function greet()
272
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
273 41
        $version = $this->getVersion();
274
        $welcome = <<<WELCOME
0 ignored issues
show
Coding Style introduced by
Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead
Loading history...
275
Yentu Database Migration Tool
276 41
Version $version
277
278
279
WELCOME;
280 41
        $this->io->output($welcome);
281 41
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
282
283 41
    public function getVersion()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
284
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
285 41
        if (defined('PHING_BUILD_VERSION')) {
286 41
            return PHING_BUILD_VERSION;
0 ignored issues
show
Bug introduced by
The constant yentu\PHING_BUILD_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
287
        } else {
288
            $version = new \SebastianBergmann\Version(Yentu::VERSION, dirname(__DIR__));
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
289
            return $version->getVersion();
290
        }
291
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
292
293
}
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...
294