Completed
Push — master ( fefd2b...bbdd37 )
by Vincenzo
02:31
created

SlimeCommand::getArg()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
4
namespace App\Lib\Slime\Console;
5
6
7
use App\Lib\Slime\Interfaces\Console\ConsoleCommand;
8
9
abstract class SlimeCommand implements ConsoleCommand
10
{
11
    protected $mandatoryArgs = [];
12
    protected $acceptedArgs = [];
13
    protected $args = [];
14
15
    public function __construct(array $args)
16
    {
17
        $this->args = $args;
18
19
        $this->parseArgs($args);
20
    }
21
22
    /**
23
     * @return int
24
     */
25
    public abstract function run();
26
27
    private function parseArgs(array $args)
28
    {
29
        foreach ($this->acceptedArgs as $acceptedArg) {
30
            if (array_key_exists($acceptedArg, $args)) {
31
                $this->args[] = $args[$acceptedArg];
32
            }
33
        }
34
    }
35
36
    protected function getArg($position)
37
    {
38
        return isset($this->args[$position]) ? $this->args[$position] : null;
39
    }
40
}