Passed
Push — master ( 472b4c...8e27d6 )
by Gabriel
04:44
created

RunCommandsTrait::create()   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 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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)
42
    {
43
        $phinx = new PhinxApplication();
44
        $command = $phinx->find($command);
45
46
        $arguments['command'] = $command;
47
        $arguments['--configuration'] = $this->getCachedConfigPath();
0 ignored issues
show
Bug introduced by
It seems like getCachedConfigPath() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

47
        /** @scrutinizer ignore-call */ 
48
        $arguments['--configuration'] = $this->getCachedConfigPath();
Loading history...
48
49
        $input = new ArrayInput($arguments);
0 ignored issues
show
Unused Code introduced by
The assignment to $input is dead and can be removed.
Loading history...
50
        /** @noinspection PhpUnhandledExceptionInspection */
51
        return $command->run(new ArrayInput($arguments), $output);
52
    }
53
}
54