|
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)) { |
|
|
|
|
|
|
34
|
|
|
$yentu->reverseCommand($command); |
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
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
|
|
|
|
This check looks for calls to
isset(...)orempty()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.