8000 [TwigBridge] Added bundle name suggestion on wrongly overrided templates paths by pmontoya · Pull Request #26919 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] Added bundle name suggestion on wrongly overrided templates paths #26919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add an entry on json export format
  • Loading branch information
Pascal Montoya committed Jun 18, 2018
commit 7d9467a3193ced99c5f7397f05351fd557c5c1c0
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGELOG
-----

* add a `workflow_metadata` function
* add bundle name suggestion on wrongly overrided templates paths
* add bundle name suggestion on wrongly overridden templates paths
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be an item under a to be added 4.2.0 section

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thank you


3.4.0
-----
Expand Down
34 changes: 27 additions & 7 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$data['tests'] = array_keys($data['tests']);
$data['loader_paths'] = $this->getLoaderPaths();
if ($wrongBundles = $this->findWrongBundleOverrides()) {
$messages = $this->buildWarningMessages($wrongBundles);
$data['warnings'] = array_reduce(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand for what we need array_reduce() here. $messages already is just an array of strings, isn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It was just dead code. Done

$messages,
function ($carry, $message) {
$carry[] = $message;

return $carry;
},
array()
);
}

$io->writeln(json_encode($data));
$this->displayAlternatives($this->findWrongBundleOverrides(), $io);

return 0;
}
Expand Down Expand Up @@ -130,7 +142,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
array_pop($rows);
$io->section('Loader Paths');
$io->table(array('Namespace', 'Paths'), $rows);
$this->displayAlternatives($this->findWrongBundleOverrides(), $io);
$messages = $this->buildWarningMessages($this->findWrongBundleOverrides());
array_walk(
$messages,
function ($message) use ($io) {
$io->warning(trim($message));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just trim in buildWarningMessages() and then iterate the array here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
);

return 0;
}
Expand Down Expand Up @@ -293,13 +311,12 @@ function ($carry, $absolutePath) use ($relativePath) {
}

if (\count($bundleNames)) {
$loadedBundles = $this->bundlesMetadata;
$notFoundBundles = array_diff_key($bundleNames, $loadedBundles);
$notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata);
if (\count($notFoundBundles)) {
$alternatives = array();
foreach ($notFoundBundles as $notFoundBundle => $path) {
$alternatives[$path] = array();
foreach ($loadedBundles as $name => $bundle) {
foreach ($this->bundlesMetadata as $name => $bundle) {
$lev = levenshtein($notFoundBundle, $name);
if ($lev <= \strlen($notFoundBundle) / 3 || false !== strpos($name, $notFoundBundle)) {
$alternatives[$path][] = $name;
Expand All @@ -312,8 +329,9 @@ function ($carry, $absolutePath) use ($relativePath) {
return $alternatives;
}

private function displayAlternatives(array $wrongBundles, SymfonyStyle $io): void
private function buildWarningMessages(array $wrongBundles): array
{
$messages = array();
foreach ($wrongBundles as $path => $alternatives) {
$message = sprintf('Path "%s" not matching any bundle found', $path);
if ($alternatives) {
Expand All @@ -326,7 +344,9 @@ private function displayAlternatives(array $wrongBundles, SymfonyStyle $io): voi
}
}
}
$io->warning(trim($message));
$messages[] = $message;
}

return $messages;
}
}
0