Completed
Pull Request — master (#4)
by
unknown
07:52
created

MigrateTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 65%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 49
ccs 13
cts 20
cp 0.65
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B migrate() 0 30 5
1
<?php
2
3
/**
4
 * This file is part of laravel-quota
5
 *
6
 * (c) David Faith <[email protected]>
7
 *
8
 * Full copyright and license information is available
9
 * in the LICENSE file distributed with this source code.
10
 */
11
12
namespace Projectmentor\Quota\Helpers;
13
14
use Illuminate\Filesystem\Filesystem;
15
use Illuminate\Filesystem\ClassFinder;
16
17
/**
18
 * This is the migrate trait.
19
 *
20
 * @author David Faith <[email protected]>
21
 */
22
trait MigrateTrait
23
{
24
25
    /**
26
     * Path to migration files to run.
27
     *
28
     * @var string
29
     */
30
    protected $migrations_path;
0 ignored issues
show
Coding Style introduced by
$migrations_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
31
32
33
    /**
34
     * Migrate All Files.
35
     *
36
     * @after
37
     *
38
     * @return void
39
     */
40 9
    public function migrate($path = null, $files = [])
41
    {
42
        //default migration path;
43 9
        $this->migrations_path = base_path('database/migrations');
44 9
        $this->migrations_path = $path ? $path : $this->migrations_path;
45
46 9
        $fileSystem = app(Filesystem::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
47 9
        $classFinder = app(ClassFinder::class);
48
49 9
        if (!empty($files)) {
50
            //run specific files
51
52
            foreach ($files as $file) {
53
                $file = $this->migrations_path . "/" . $file;
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...
54
55
                $fileSystem->requireOnce($file);
56
                $migrationClass = $classFinder->findClass($file);
57
                (new $migrationClass)->up();
58
            }
59
        } else {
60 9
            \Log::info($fileSystem->files($this->migrations_path));
61
62 9
            foreach ($fileSystem->files($this->migrations_path) as $file) {
63 9
                $fileSystem->requireOnce($file);
64
//                var_dump($file);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
65 9
                $migrationClass = $classFinder->findClass($file);
66 9
                (new $migrationClass)->up();
67 9
            }
68
        }
69 9
    }
70
}
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...
71