1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\DefaultPhpRepository\Helper; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
use Symfony\Component\Console\Question\Question; |
8
|
|
|
use Yoanm\DefaultPhpRepository\Model\Template; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CommandHelper |
12
|
|
|
*/ |
13
|
|
|
class CommandHelper |
14
|
|
|
{ |
15
|
|
|
const OUTPUT_LEVEL_SPACE = ' '; |
16
|
|
|
|
17
|
|
|
/** @var InputInterface */ |
18
|
|
|
private $input; |
19
|
|
|
/** @var OutputInterface */ |
20
|
|
|
private $output; |
21
|
|
|
/** @var QuestionHelper */ |
22
|
|
|
private $questionHelper; |
23
|
|
|
/** @var TemplateHelper */ |
24
|
|
|
private $templateHelper; |
25
|
|
|
/** @var Template[] */ |
26
|
|
|
private $templateList; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param InputInterface $input |
30
|
|
|
* @param OutputInterface $output |
31
|
|
|
* @param TemplateHelper $templateHelper |
32
|
|
|
* @param QuestionHelper $questionHelper |
33
|
|
|
* @param Template[] $templateList |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
InputInterface $input, |
37
|
|
|
OutputInterface $output, |
38
|
|
|
TemplateHelper $templateHelper, |
39
|
|
|
QuestionHelper $questionHelper, |
40
|
|
|
array $templateList |
41
|
|
|
) { |
42
|
|
|
$this->input = $input; |
43
|
|
|
$this->output = $output; |
44
|
|
|
|
45
|
|
|
$this->questionHelper = $questionHelper; |
46
|
|
|
$this->templateHelper = $templateHelper; |
47
|
|
|
|
48
|
|
|
$this->templateList = $templateList; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return Template[] |
53
|
|
|
*/ |
54
|
|
|
public function getTemplateList() |
55
|
|
|
{ |
56
|
|
|
return $this->templateList; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Template $template |
61
|
|
|
* @param string $currentType |
62
|
|
|
*/ |
63
|
|
|
public function displayHeader(Template $template, $currentType) |
64
|
|
|
{ |
65
|
|
|
if (null === $currentType || !preg_match(sprintf('#^%s\.#', preg_quote($currentType)), $template->getId())) { |
66
|
|
|
$header = ucwords($this->resolveCurrentType($template)); |
67
|
|
|
|
68
|
|
|
if ('Git' === $header) { |
69
|
|
|
$header = 'Git/Github'; |
70
|
|
|
} elseif ('Ci' === $header) { |
71
|
|
|
$header = 'Continuous integration'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->display(sprintf('<info>%s :</info>', $header), 1); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $message |
80
|
|
|
* @param int $level |
81
|
|
|
*/ |
82
|
|
|
public function display($message, $level = 0, $ln = true) |
83
|
|
|
{ |
84
|
|
|
$message = sprintf( |
85
|
|
|
'%s%s', |
86
|
|
|
str_repeat(self::OUTPUT_LEVEL_SPACE, $level), |
87
|
|
|
$message |
88
|
|
|
); |
89
|
|
|
if (true === $ln) { |
90
|
|
|
$this->output->writeln($message); |
91
|
|
|
} else { |
92
|
|
|
$this->output->write($message); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param Template $template |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function resolveCurrentType(Template $template) |
102
|
|
|
{ |
103
|
|
|
$currentType = preg_replace('#^([^\.]+)\..*#', '\1', $template->getId()); |
104
|
|
|
|
105
|
|
|
return $currentType; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param Question $question |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function ask(Question $question) |
114
|
|
|
{ |
115
|
|
|
return $this->questionHelper->ask($this->input, $this->output, $question); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param Template $template |
120
|
|
|
*/ |
121
|
|
|
public function dump(Template $template) |
122
|
|
|
{ |
123
|
|
|
$templateId = $template->getSource(); |
124
|
|
|
if (null !== $template->getNamespace()) { |
125
|
|
|
$templateId = sprintf('@%s/%s', $template->getNamespace(), $template->getSource()); |
126
|
|
|
} |
127
|
|
|
$this->templateHelper->dump($templateId, $this->resolveTargetPath($template)); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.