|
6 | 6 |
|
7 | 7 | use AbstractComponentConfiguration\AbstractComponentConfiguration;
|
8 | 8 | use App\{
|
| 9 | + Benchmark\BenchmarkType, |
9 | 10 | Command\AbstractCommand,
|
10 | 11 | Command\Validate\ValidateConfigurationComponentSourceCodeUrlsCommand,
|
11 | 12 | ComponentConfiguration\ComponentConfiguration
|
@@ -76,68 +77,88 @@ function () use ($url) {
|
76 | 77 |
|
77 | 78 | protected function getSourceCodeUrls(): array
|
78 | 79 | {
|
79 |
| - $urls = ComponentConfiguration::getSourceCodeUrls(); |
80 |
| - $return = [ |
| 80 | + $return = $this->getSourceCodeUrlsToAsk( |
| 81 | + ComponentConfiguration::getBenchmarkType(), |
| 82 | + ComponentConfiguration::getComponentType(), |
| 83 | + ComponentConfiguration::getSourceCodeUrls() |
| 84 | + ); |
| 85 | + |
| 86 | + foreach ($return as &$url) { |
| 87 | + $violations = ValidateConfigurationComponentSourceCodeUrlsCommand::validateSourCodeUrl($url['url']); |
| 88 | + $showWarning = false; |
| 89 | + do { |
| 90 | + if (count($violations) > 0 && $showWarning) { |
| 91 | + $errors = []; |
| 92 | + /** @var ConstraintViolationInterface $violation */ |
| 93 | + foreach ($violations as $violation) { |
| 94 | + $errors[] = $violation->getMessage(); |
| 95 | + } |
| 96 | + $this->warning(implode(', ', $errors)); |
| 97 | + } |
| 98 | + |
| 99 | + $url['url'] = $this->question( |
| 100 | + $url['question'], |
| 101 | + substr($url['url'] ?? '', 0, 4) === '____' ? null : $url['url'] |
| 102 | + ); |
| 103 | + |
| 104 | + $showWarning = true; |
| 105 | + } while ( |
| 106 | + count( |
| 107 | + $violations = ValidateConfigurationComponentSourceCodeUrlsCommand::validateSourCodeUrl($url['url']) |
| 108 | + ) > 0 |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + return $return; |
| 113 | + } |
| 114 | + |
| 115 | + protected function getSourceCodeUrlsToAsk(int $benchmarkType, int $componentType, array $defaultUrls): array |
| 116 | + { |
| 117 | + $availableUrls = [ |
| 118 | + 'entryPoint' => [ |
| 119 | + 'question' => 'URL to entry point code?', |
| 120 | + 'variable' => '____PHPBENCHMARKS_ENTRY_POINT_URL____' |
| 121 | + ], |
| 122 | + 'template' => [ |
| 123 | + 'question' => 'URL to template code?', |
| 124 | + 'variable' => '____PHPBENCHMARKS_TEMPLATE_URL____' |
| 125 | + ], |
81 | 126 | 'route' => [
|
82 | 127 | 'question' => 'URL to benchmark route code?',
|
83 |
| - 'url' => $urls['route'] ?? null, |
84 | 128 | 'variable' => '____PHPBENCHMARKS_ROUTE_SOURCE_CODE_URL____'
|
85 | 129 | ],
|
86 | 130 | 'controller' => [
|
87 | 131 | 'question' => 'URL to Controller code?',
|
88 |
| - 'url' => $urls['controller'] ?? null, |
89 | 132 | 'variable' => '____PHPBENCHMARKS_CONTROLLER_SOURCE_CODE_URL____'
|
90 | 133 | ],
|
91 | 134 | 'randomizeLanguageDispatchEvent' => [
|
92 | 135 | 'question' => 'URL to code who dispatch event to randomize language?',
|
93 |
| - 'url' => $urls['randomizeLanguageDispatchEvent'] ?? null, |
94 | 136 | 'variable' => '____PHPBENCHMARKS_RANDOMIZE_LANGUAGE_DISPATCH_EVENT_SOURCE_CODE_URL____'
|
95 | 137 | ],
|
96 | 138 | 'randomizeLanguageEventListener' => [
|
97 | 139 | 'question' => 'URL to code who listen event to randomize language?',
|
98 |
| - 'url' => $urls['randomizeLanguageEventListener'] ?? null, |
99 | 140 | 'variable' => '____PHPBENCHMARKS_RANDOMIZE_LANGUAGE_EVENT_LISTENER_SOURCE_CODE_URL____'
|
100 | 141 | ],
|
101 | 142 | 'translations' => [
|
102 | 143 | 'question' => 'URL to en_GB translations code?',
|
103 |
| - 'url' => $urls['translations'] ?? null, |
104 | 144 | 'variable' => '____PHPBENCHMARKS_TRANSLATIONS_SOURCE_CODE_URL____'
|
105 | 145 | ],
|
106 | 146 | 'translate' => [
|
107 | 147 | 'question' => 'URL to code who translate translated.1000 key?',
|
108 |
| - 'url' => $urls['translate'] ?? null, |
109 | 148 | 'variable' => '____PHPBENCHMARKS_TRANSLATE_SOURCE_CODE_URL____'
|
110 | 149 | ],
|
111 | 150 | 'serialize' => [
|
112 | 151 | 'question' => 'URL to code who serialize User?',
|
113 |
| - 'url' => $urls['serialize'] ?? null, |
114 | 152 | 'variable' => '____PHPBENCHMARKS_SERIALIZE_SOURCE_CODE_URL____'
|
115 | 153 | ]
|
116 | 154 | ];
|
117 | 155 |
|
118 |
| - foreach ($return as &$url) { |
119 |
| - $violations = ValidateConfigurationComponentSourceCodeUrlsCommand::validateSourCodeUrl($url['url']); |
120 |
| - $showWarning = false; |
121 |
| - do { |
122 |
| - if (count($violations) > 0) { |
123 |
| - if ($showWarning) { |
124 |
| - $errors = []; |
125 |
| - /** @var ConstraintViolationInterface $violation */ |
126 |
| - foreach ($violations as $violation) { |
127 |
| - $errors[] = $violation->getMessage(); |
128 |
| - } |
129 |
| - $this->warning(implode(', ', $errors)); |
130 |
| - } |
131 |
| - |
132 |
| - $url['url'] = $this->question($url['question']); |
133 |
| - } |
134 |
| - |
135 |
| - $showWarning = true; |
136 |
| - } while ( |
137 |
| - count( |
138 |
| - $violations = ValidateConfigurationComponentSourceCodeUrlsCommand::validateSourCodeUrl($url['url']) |
139 |
| - ) > 0 |
140 |
| - ); |
| 156 | + $return = []; |
| 157 | + foreach (BenchmarkType::getSourceCodeUrlIds($benchmarkType, $componentType) as $urlId) { |
| 158 | + if (array_key_exists($urlId, $availableUrls) === false) { |
| 159 | + throw new \Exception('Unknown url id "' . $urlId . '".'); |
| 160 | + } |
| 161 | + $return[$urlId] = array_merge($availableUrls[$urlId], ['url' => $defaultUrls[$urlId] ?? null]); |
141 | 162 | }
|
142 | 163 |
|
143 | 164 | return $return;
|
|
0 commit comments