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

RunCommandsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 40
ccs 2
cts 11
cp 0.1818
rs 10
c 2
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 11 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)
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