1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cecil\Command; |
4
|
|
|
|
5
|
|
|
use Cecil\Builder; |
6
|
|
|
use Symfony\Component\Console\Command\Command as BaseCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Yaml\Exception\ParseException; |
10
|
|
|
use Symfony\Component\Yaml\Yaml; |
11
|
|
|
|
12
|
|
|
class Command extends BaseCommand |
13
|
|
|
{ |
14
|
|
|
const CONFIG_FILE = 'config.yml'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $path; |
20
|
|
|
/** |
21
|
|
|
* @var Builder |
22
|
|
|
*/ |
23
|
|
|
protected $builder; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritDoc} |
27
|
|
|
*/ |
28
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
$this->path = $input->getArgument('path'); |
|
|
|
|
31
|
|
|
$this->path = realpath($this->path); |
32
|
|
|
$this->path = str_replace(DIRECTORY_SEPARATOR, '/', $this->path); |
33
|
|
|
|
34
|
|
|
parent::initialize($input, $output); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function getPath() |
41
|
|
|
{ |
42
|
|
|
return $this->path; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param OutputInterface $output |
47
|
|
|
* @param array $config |
48
|
|
|
* @param array $options |
49
|
|
|
* |
50
|
|
|
* @return Builder |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function getBuilder( |
53
|
|
|
OutputInterface $output, |
54
|
|
|
array $config = ['debug' => false], |
55
|
|
|
array $options = ['verbosity' => Builder::VERBOSITY_NORMAL] |
56
|
|
|
) { |
57
|
|
|
if (!file_exists($this->getPath() . '/' . self::CONFIG_FILE)) { |
58
|
|
|
throw new \Exception(sprintf('Config file not found in "%s"!', $this->getPath())); |
59
|
|
|
} |
60
|
|
|
// verbosity: verbose |
61
|
|
|
if ($options['verbosity'] == Builder::VERBOSITY_VERBOSE) { |
62
|
|
|
$this->verbose = true; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
// verbosity: quiet |
65
|
|
|
if ($options['verbosity'] == Builder::VERBOSITY_QUIET) { |
66
|
|
|
$this->quiet = true; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
try { |
70
|
|
|
$configFile = Yaml::parse(file_get_contents($this->getPath() . '/' . self::CONFIG_FILE)); |
71
|
|
|
$config = array_replace_recursive($configFile, $config); |
72
|
|
|
$this->builder = (new Builder($config, $this->messageCallback($output))) |
73
|
|
|
->setSourceDir($this->getPath()) |
74
|
|
|
->setDestinationDir($this->getPath()); |
75
|
|
|
} catch (ParseException $e) { |
76
|
|
|
throw new \Exception(sprintf('Config file parse error: %s', $e->getMessage())); |
77
|
|
|
} catch (\Exception $e) { |
78
|
|
|
throw new \Exception(sprintf($e->getMessage())); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this->builder; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Custom message callback function. |
86
|
|
|
* |
87
|
|
|
* @param OutputInterface $output |
88
|
|
|
*/ |
89
|
|
|
public function messageCallback(OutputInterface $output) |
90
|
|
|
{ |
91
|
|
|
return function ($code, $message = '', $itemsCount = 0, $itemsMax = 0) use ($output) { |
92
|
|
|
if ($this->quiet) { |
93
|
|
|
return; |
94
|
|
|
} else { |
95
|
|
|
if (strpos($code, '_PROGRESS') !== false) { |
96
|
|
|
if ($this->verbose) { |
97
|
|
|
if ($itemsCount > 0) { |
98
|
|
|
//$this->wlDone(sprintf('(%u/%u) %s', $itemsCount, $itemsMax, $message)); |
99
|
|
|
$output->writeln(sprintf('(%u/%u) %s', $itemsCount, $itemsMax, $message)); |
100
|
|
|
|
101
|
|
|
return; |
102
|
|
|
} |
103
|
|
|
//$this->wlDone("$message"); |
104
|
|
|
$output->writeln("$message"); |
105
|
|
View Code Duplication |
} else { |
|
|
|
|
106
|
|
|
if (isset($itemsCount) && $itemsMax > 0) { |
107
|
|
|
//$this->printProgressBar($itemsCount, $itemsMax, $message); |
108
|
|
|
$output->writeln("$message"); |
109
|
|
|
} else { |
110
|
|
|
//$this->wl($message); |
111
|
|
|
$output->writeln("$message"); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} elseif (strpos($code, '_ERROR') !== false) { |
115
|
|
|
//$this->wlError($message); |
116
|
|
|
$output->writeln("$message"); |
117
|
|
|
} elseif ($code == 'TIME') { |
118
|
|
|
//$this->wl($message); |
119
|
|
|
$output->writeln("$message"); |
120
|
|
|
} else { |
121
|
|
|
//$this->wlAnnonce($message); |
122
|
|
|
$output->writeln("$message"); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
}; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.