Completed
Branch dev (b4f2c3)
by James Ekow Abaka
03:46
created

Cli   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
C run() 0 44 13
1
<?php
2
3
namespace yentu;
4
5
use clearice\argparser\ArgumentParser;
6
use clearice\io\Io;
7
use yentu\commands\Command;
8
9
class Cli
10
{
11
    private $command;
12
    private $io;
13
    private $argumentParser;
14
15
    public function __construct(Io $io, Command $command = null, ArgumentParser $argumentParser)
16
    {
17
        $this->command = $command;
18
        $this->io = $io;
19
        $this->argumentParser = $argumentParser;
20
    }
21
22
    public function run()
23
    {
24
        if($this->command) {
25
            try {
26
                $this->command->run();
27
            } catch (\yentu\exceptions\CommandException $e) {
28
                $this->io->resetOutputLevel();
29
                $this->io->error("Error! " . $e->getMessage() . "\n");
30
            } catch (\ntentan\atiaa\exceptions\DatabaseDriverException $e) {
31
                $this->io->resetOutputLevel();
32
                $this->io->error("Database driver failed: " . $e->getMessage() . "\n");
33
                if (isset($command)) {
0 ignored issues
show
Bug introduced by
The variable $command seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
34
                    $yentu->reverseCommand($command);
0 ignored issues
show
Bug introduced by
The variable $yentu does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
35
                }
36
            } catch (\yentu\exceptions\DatabaseManipulatorException $e) {
37
                $this->io->resetOutputLevel();
38
                $this->io->error("Failed to perform database action: " . $e->getMessage() . "\n");
39
                if (isset($command)) {
40
                    $yentu->reverseCommand($command);
41
                }
42
            } catch (\ntentan\atiaa\DescriptionException $e) {
0 ignored issues
show
Bug introduced by
The class ntentan\atiaa\DescriptionException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
43
                $this->io->resetOutputLevel();
44
                $this->io->error("Failed to perform database action: " . $e->getMessage() . "\n");
45
                if (isset($command)) {
46
                    $yentu->reverseCommand($command);
47
                }
48
            } catch (\yentu\exceptions\SyntaxErrorException $e) {
49
                $this->io->resetOutputLevel();
50
                $this->io->error("Error found in syntax: {$e->getMessage()}\n");
51
                if (isset($command)) {
52
                    $yentu->reverseCommand($command);
53
                }
54
            } catch (\PDOException $e) {
55
                $this->io->resetOutputLevel();
56
                $this->io->error("Failed to connect to database: {$e->getMessage()}\n");
57
            } catch (\ntentan\utils\exceptions\FileNotFoundException $e) {
58
                $this->io->resetOutputLevel();
59
                $this->io->error($e->getMessage() . "\n");        
60
            }
61
    
62
        } else {
63
            $this->io->error($this->argumentParser->getHelpMessage());
64
        }
65
    }
66
}
67