minor #33504 SCA: minor code tweaks (kalessil)

This PR was squashed before being merged into the 3.4 branch (closes #33504).

Discussion
----------

SCA: minor code tweaks

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Minor code tweaks: disabled sorting in glob (the order is not important there), used implode() negative index support in order to drop an array_pop() call.

Commits
-------

32ea449679 SCA: minor code tweaks
This commit is contained in:
Fabien Potencier 2019-09-08 19:26:35 +02:00
commit 6f332ce0e0
4 changed files with 6 additions and 7 deletions

View File

@ -260,11 +260,11 @@ abstract class AbstractDoctrineExtension extends Extension
$configPath = $this->getMappingResourceConfigDirectory();
$extension = $this->getMappingResourceExtension();
if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml')) {
if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml', GLOB_NOSORT)) {
$driver = 'xml';
} elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.yml')) {
} elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.yml', GLOB_NOSORT)) {
$driver = 'yml';
} elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.php')) {
} elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.php', GLOB_NOSORT)) {
$driver = 'php';
} else {
// add the closest existing directory as a resource

View File

@ -1098,8 +1098,7 @@ class Application
*/
public function extractNamespace($name, $limit = null)
{
$parts = explode(':', $name);
array_pop($parts);
$parts = explode(':', $name, -1);
return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit));
}

View File

@ -673,7 +673,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
static $legacyContainers = [];
$oldContainerDir = \dirname($oldContainer->getFileName());
$legacyContainers[$oldContainerDir.'.legacy'] = true;
foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy') as $legacyContainer) {
foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy', GLOB_NOSORT) as $legacyContainer) {
if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
(new Filesystem())->remove(substr($legacyContainer, 0, -7));
}

View File

@ -42,7 +42,7 @@ class LocaleScanner
*/
public function scanLocales($sourceDir)
{
$locales = glob($sourceDir.'/*.txt');
$locales = glob($sourceDir.'/*.txt', GLOB_NOSORT);
// Remove file extension and sort
array_walk($locales, function (&$locale) { $locale = basename($locale, '.txt'); });