@@ -208,8 +208,8 @@ private function displayGeneralText(SymfonyStyle $io, string $filter = null)
208208 $ io ->table (array ('Namespace ' , 'Paths ' ), $ this ->buildTableRows ($ paths ));
209209 }
210210
211- if ($ wronBundles = $ this ->findWrongBundleOverrides ()) {
212- foreach ($ this ->buildWarningMessages ($ wronBundles ) as $ message ) {
211+ if ($ wrongBundles = $ this ->findWrongBundleOverrides ()) {
212+ foreach ($ this ->buildWarningMessages ($ wrongBundles ) as $ message ) {
213213 $ io ->warning ($ message );
214214 }
215215 }
@@ -253,13 +253,7 @@ private function getLoaderPaths(string $name = null): array
253253 }
254254
255255 foreach ($ namespaces as $ namespace ) {
256- $ paths = array_map (function ($ path ) {
257- if (null !== $ this ->projectDir && 0 === strpos ($ path , $ this ->projectDir )) {
258- $ path = ltrim (substr ($ path , \strlen ($ this ->projectDir )), \DIRECTORY_SEPARATOR );
259- }
260-
261- return $ path ;
262- }, $ loader ->getPaths ($ namespace ));
256+ $ paths = array_map (array ($ this , 'getRelativePath ' ), $ loader ->getPaths ($ namespace ));
263257
264258 if (FilesystemLoader::MAIN_NAMESPACE === $ namespace ) {
265259 $ namespace = '(None) ' ;
@@ -368,53 +362,38 @@ private function findWrongBundleOverrides(): array
368362
369363 if ($ this ->rootDir && $ this ->projectDir ) {
370364 $ folders = glob ($ this ->rootDir .'/Resources/*/views ' , GLOB_ONLYDIR );
371- $ relativePath = ltrim (substr ($ this ->rootDir .' / Resources/ ' , \strlen ($ this ->projectDir )), \DIRECTORY_SEPARATOR );
372- $ bundleNames = array_reduce (
373- $ folders ,
374- function ( $ carry , $ absolutePath ) use ( $ relativePath ) {
375- if ( 0 === strpos ( $ absolutePath , $ this -> projectDir )) {
376- $ name = basename ( \dirname ( $ absolutePath )) ;
377- $ path = $ relativePath . $ name ;
378- $ carry [ $ name] = $ path ;
379- }
365+ $ relativePath = ltrim (substr ($ this ->rootDir .\ DIRECTORY_SEPARATOR . ' Resources/ ' , \strlen ($ this ->projectDir )), \DIRECTORY_SEPARATOR );
366+ $ bundleNames = array_reduce ($ folders , function ( $ carry , $ absolutePath ) use ( $ relativePath ) {
367+ if ( 0 === strpos ( $ absolutePath , $ this -> projectDir )) {
368+ $ name = basename ( \dirname ( $ absolutePath ));
369+ $ path = ltrim ( $ relativePath . $ name , \ DIRECTORY_SEPARATOR );
370+ $ carry [ $ name] = $ path ;
371+
372+ @ trigger_error ( sprintf ( ' Templates directory "%s" is deprecated since Symfony 4.2, use "%s" instead. ' , $ absolutePath , $ this -> twigDefaultPath . ' /bundles/ ' . $ name), E_USER_DEPRECATED ) ;
373+ }
380374
381- return $ carry ;
382- },
383- $ bundleNames
384- );
375+ return $ carry ;
376+ }, $ bundleNames );
385377 }
386378
387379 if ($ this ->twigDefaultPath && $ this ->projectDir ) {
388380 $ folders = glob ($ this ->twigDefaultPath .'/bundles/* ' , GLOB_ONLYDIR );
389- $ relativePath = ltrim (substr ($ this ->twigDefaultPath .'/bundles ' , \strlen ($ this ->projectDir )), \DIRECTORY_SEPARATOR );
390- $ bundleNames = array_reduce (
391- $ folders ,
392- function ($ carry , $ absolutePath ) use ($ relativePath ) {
393- if (0 === strpos ($ absolutePath , $ this ->projectDir )) {
394- $ path = ltrim (substr ($ absolutePath , \strlen ($ this ->projectDir )), \DIRECTORY_SEPARATOR );
395- $ name = ltrim (substr ($ path , \strlen ($ relativePath )), \DIRECTORY_SEPARATOR );
396- $ carry [$ name ] = $ path ;
397- }
398-
399- return $ carry ;
400- },
401- $ bundleNames
402- );
403- }
404-
405- if (\count ($ bundleNames )) {
406- $ notFoundBundles = array_diff_key ($ bundleNames , $ this ->bundlesMetadata );
407- if (\count ($ notFoundBundles )) {
408- $ alternatives = array ();
409- foreach ($ notFoundBundles as $ notFoundBundle => $ path ) {
410- $ alternatives [$ path ] = array ();
411- foreach ($ this ->bundlesMetadata as $ name => $ bundle ) {
412- $ lev = levenshtein ($ notFoundBundle , $ name );
413- if ($ lev <= \strlen ($ notFoundBundle ) / 3 || false !== strpos ($ name , $ notFoundBundle )) {
414- $ alternatives [$ path ][] = $ name ;
415- }
416- }
381+ $ relativePath = ltrim (substr ($ this ->twigDefaultPath .'/bundles/ ' , \strlen ($ this ->projectDir )), \DIRECTORY_SEPARATOR );
382+ $ bundleNames = array_reduce ($ folders , function ($ carry , $ absolutePath ) use ($ relativePath ) {
383+ if (0 === strpos ($ absolutePath , $ this ->projectDir )) {
384+ $ name = basename ($ absolutePath );
385+ $ path = ltrim ($ relativePath .$ name , \DIRECTORY_SEPARATOR );
386+ $ carry [$ name ] = $ path ;
417387 }
388+
389+ return $ carry ;
390+ }, $ bundleNames );
391+ }
392+
393+ if ($ notFoundBundles = array_diff_key ($ bundleNames , $ this ->bundlesMetadata )) {
394+ $ alternatives = array ();
395+ foreach ($ notFoundBundles as $ notFoundBundle => $ path ) {
396+ $ alternatives [$ path ] = $ this ->findAlternatives ($ notFoundBundle , array_keys ($ this ->bundlesMetadata ));
418397 }
419398 }
420399
0 commit comments