Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54f66a7

Browse files
author
Pascal Montoya
committed
Add an entry on json export format
1 parent 9dad025 commit 54f66a7

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
-----
66

77
* add a `workflow_metadata` function
8-
* add bundle name suggestion on wrongly overrided templates paths
8+
* add bundle name suggestion on wrongly overridden templates paths
99

1010
3.4.0
1111
-----

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
8888
}
8989
$data['tests'] = array_keys($data['tests']);
9090
$data['loader_paths'] = $this->getLoaderPaths();
91+
if ($wrongBundles = $this->findWrongBundleOverrides()) {
92+
$messages = $this->buildWarningMessages($wrongBundles);
93+
$data['warnings'] = array_reduce(
94+
$messages,
95+
function ($carry, $message) {
96+
$carry[] = $message;
97+
98+
return $carry;
99+
},
100+
array()
101+
);
102+
}
103+
91104
$io->writeln(json_encode($data));
92-
$this->displayAlternatives($this->findWrongBundleOverrides(), $io);
93105

94106
return 0;
95107
}
@@ -130,7 +142,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
130142
array_pop($rows);
131143
$io->section('Loader Paths');
132144
$io->table(array('Namespace', 'Paths'), $rows);
133-
$this->displayAlternatives($this->findWrongBundleOverrides(), $io);
145+
$messages = $this->buildWarningMessages($this->findWrongBundleOverrides());
146+
array_walk(
147+
$messages,
148+
function ($message) use ($io) {
149+
$io->warning(trim($message));
150+
}
151+
);
134152

135153
return 0;
136154
}
@@ -293,13 +311,12 @@ function ($carry, $absolutePath) use ($relativePath) {
293311
}
294312

295313
if (\count($bundleNames)) {
296-
$loadedBundles = $this->bundlesMetadata;
297-
$notFoundBundles = array_diff_key($bundleNames, $loadedBundles);
314+
$notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata);
298315
if (\count($notFoundBundles)) {
299316
$alternatives = array();
300317
foreach ($notFoundBundles as $notFoundBundle => $path) {
301318
$alternatives[$path] = array();
302-
foreach ($loadedBundles as $name => $bundle) {
319+
foreach ($this->bundlesMetadata as $name => $bundle) {
303320
$lev = levenshtein($notFoundBundle, $name);
304321
if ($lev <= \strlen($notFoundBundle) / 3 || false !== strpos($name, $notFoundBundle)) {
305322
$alternatives[$path][] = $name;
@@ -312,8 +329,9 @@ function ($carry, $absolutePath) use ($relativePath) {
312329
return $alternatives;
313330
}
314331

315-
private function displayAlternatives(array $wrongBundles, SymfonyStyle $io): void
332+
private function buildWarningMessages(array $wrongBundles): array
316333
{
334+
$messages = array();
317335
foreach ($wrongBundles as $path => $alternatives) {
318336
$message = sprintf('Path "%s" not matching any bundle found', $path);
319337
if ($alternatives) {
@@ -326,7 +344,9 @@ private function displayAlternatives(array $wrongBundles, SymfonyStyle $io): voi
326344
}
327345
}
328346
}
329-
$io->warning(trim($message));
347+
$messages[] = $message;
330348
}
349+
350+
return $messages;
331351
}
332352
}

0 commit comments

Comments
 (0)