Cli   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleAction() 0 10 2
A __construct() 0 14 1
1
<?php
2
3
namespace Src\Cli;
4
5
use Luke\Migration\Config\FileCreate;
6
use Luke\Migration\Config\MigrationFile;
7
8
class Cli
9
{
10
    public $array = [];
11
12
    public function __construct($commnad)
13
    {
14
        $this->array = [
15
            "--migration" => function ($file) {
16
                (new FileCreate)->createFile($file);
17
                echo "\e[32mMigration " . $file . " on successfully";
18
            },
19
            "--migrate" => function () {
20
                echo "\e[32mStarting the migration\n";
21
                (new MigrationFile)->actionMigration();
22
            }
23
        ];
24
25
        $this->handleAction($commnad);
26
    }
27
28
    private function handleAction($commnad)
29
    {
30
        try {
31
            unset($commnad[0]);
32
            $commnad = implode(" ", $commnad);
33
            $values = explode("=", $commnad);
34
            $function = $this->array[$values[0]];
35
            $function($values[1] ?? null);
36
        } catch (\Exception $e) {
37
            throw new \Exception($e->getMessage);
0 ignored issues
show
Bug introduced by
The property getMessage does not seem to exist on Exception.
Loading history...
38
        }
39
    }
40
}
41