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

SlimeCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
run() 0 1 ?
A parseArgs() 0 8 3
A getArg() 0 4 2
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
}