Passed
Push — master ( 28f242...472b4c )
by Gabriel
04:44
created

RunCommandsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 42
ccs 2
cts 8
cp 0.25
rs 10
c 1
b 0
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A migrate() 0 3 1
A create() 0 3 1
A runCommand() 0 13 1
1
<?php
2
3
namespace ByTIC\Migrations\Migrator\Traits;
4
5
use Phinx\Console\PhinxApplication;
6
use Symfony\Component\Console\Input\ArrayInput;
7
8
/**
9
 * Trait RunCommandsTrait
10
 * @package ByTIC\Migrations\Migrator\Traits
11
 */
12
trait RunCommandsTrait
13
{
14
    /**
15
     * @param array $arguments
16
     * @param $output
17
     * @return int
18
     */
19 1
    public function migrate($arguments = [], $output = null)
20
    {
21 1
        return $this->runCommand('migrate', $arguments, $output);
22
    }
23
24
    /**
25
     * @param array $arguments
26
     * @param $output
27
     * @return int
28
     */
29
    public function create($arguments = [], $output = null)
30
    {
31
        return $this->runCommand('create', $arguments, $output);
32
    }
33
34
    /**
35
     * @param $command
36
     * @param array $arguments
37
     * @param $output
38
     * @return int
39
     * @noinspection PhpDocMissingThrowsInspection
40
     */
41
    protected function runCommand($command, $arguments = [], $output = null)
0 ignored issues
show
Unused Code introduced by
The parameter $output is not used and could be removed. ( Ignorable by Annotation )

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

41
    protected function runCommand($command, $arguments = [], /** @scrutinizer ignore-unused */ $output = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        $phinx = new PhinxApplication();
44
        $command = $phinx->find($command);
0 ignored issues
show
Unused Code introduced by
The assignment to $command is dead and can be removed.
Loading history...
45
46
        var_dump($arguments);die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Security Debugging Code introduced by
var_dump($arguments) looks like debug code. Are you sure you do not want to remove it?
Loading history...
47
48
        $arguments['command'] = $command;
0 ignored issues
show
Unused Code introduced by
$arguments['command'] = $command is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
49
        $arguments['--configuration'] = $this->getCachedConfigPath();
50
51
        $input = new ArrayInput($arguments);
52
        /** @noinspection PhpUnhandledExceptionInspection */
53
        return $command->run(new ArrayInput($arguments), $output);
54
    }
55
}
56