Skip to content

Commit

Permalink
minor #33527 Dirname simplification (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.3 branch.

Discussion
----------

Dirname simplification

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

Commits
-------

c4d44eb Simplify usage of dirname()
  • Loading branch information
fabpot committed Sep 10, 2019
2 parents 5a06f94 + c4d44eb commit 2c87f69
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Expand Up @@ -21,6 +21,7 @@ return PhpCsFixer\Config::create()
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true],
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'combine_nested_dirname' => true,
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
Expand Up @@ -269,7 +269,7 @@ private static function getVendors()
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName()));
$v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) {
self::$vendors[] = $v;
$loader = require $v.'/autoload.php';
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/Client.php
Expand Up @@ -169,7 +169,7 @@ protected function getScript($request)
foreach (get_declared_classes() as $class) {
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$file = \dirname(\dirname($r->getFileName())).'/autoload.php';
$file = \dirname($r->getFileName(), 2).'/autoload.php';
if (file_exists($file)) {
$requires .= 'require_once '.var_export($file, true).";\n";
}
Expand Down
Expand Up @@ -1114,7 +1114,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) {
$r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException');

$dirs[] = $transPaths[] = \dirname(\dirname($r->getFileName())).'/Resources/translations';
$dirs[] = $transPaths[] = \dirname($r->getFileName(), 2).'/Resources/translations';
}
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
$rootDir = $container->getParameter('kernel.root_dir');
Expand Down
Expand Up @@ -64,7 +64,7 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
// check that app kernel file present in meta file of container's cache
$containerClass = $this->kernel->getContainer()->getParameter('kernel.container_class');
$containerRef = new \ReflectionClass($containerClass);
$containerFile = \dirname(\dirname($containerRef->getFileName())).'/'.$containerClass.'.php';
$containerFile = \dirname($containerRef->getFileName(), 2).'/'.$containerClass.'.php';
$containerMetaFile = $containerFile.'.meta';
$kernelRef = new \ReflectionObject($this->kernel);
$kernelFile = $kernelRef->getFileName();
Expand Down
Expand Up @@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');

$coreThemePath = \dirname(\dirname($reflClass->getFileName())).'/Resources/views/Form';
$coreThemePath = \dirname($reflClass->getFileName(), 2).'/Resources/views/Form';
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', [$coreThemePath]);

$paths = $container->getDefinition('twig.template_iterator')->getArgument(2);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Resource/ComposerResource.php
Expand Up @@ -60,7 +60,7 @@ private static function refresh()
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName()));
$v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) {
self::$runtimeVendors[$v] = @filemtime($v.'/composer/installed.json');
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public static function setUpBeforeClass(): void
}

if ($function[0] instanceof ComposerClassLoader) {
$function[0]->add('Symfony_Component_Debug_Tests_Fixtures', \dirname(\dirname(\dirname(\dirname(\dirname(__DIR__))))));
$function[0]->add('Symfony_Component_Debug_Tests_Fixtures', \dirname(__DIR__, 5));
break;
}
}
Expand Down
Expand Up @@ -105,7 +105,7 @@ public function testDumpRelativeDir()
$container->setParameter('foo', 'wiz'.\dirname(__DIR__));
$container->setParameter('bar', __DIR__);
$container->setParameter('baz', '%bar%/PhpDumperTest.php');
$container->setParameter('buz', \dirname(\dirname(__DIR__)));
$container->setParameter('buz', \dirname(__DIR__, 2));
$container->compile();

$dumper = new PhpDumper($container);
Expand Down
Expand Up @@ -29,15 +29,15 @@ public function provideTranslationFiles()
{
return array_map(
function ($filePath) { return (array) $filePath; },
glob(\dirname(\dirname(__DIR__)).'/Resources/translations/*.xlf')
glob(\dirname(__DIR__, 2).'/Resources/translations/*.xlf')
);
}

public function testNorwegianAlias()
{
$this->assertFileEquals(
\dirname(\dirname(__DIR__)).'/Resources/translations/validators.nb.xlf',
\dirname(\dirname(__DIR__)).'/Resources/translations/validators.no.xlf',
\dirname(__DIR__, 2).'/Resources/translations/validators.nb.xlf',
\dirname(__DIR__, 2).'/Resources/translations/validators.no.xlf',
'The NO locale should be an alias for the NB variant of the Norwegian language.'
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Client.php
Expand Up @@ -90,7 +90,7 @@ protected function getScript($request)
foreach (get_declared_classes() as $class) {
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$file = \dirname(\dirname($r->getFileName())).'/autoload.php';
$file = \dirname($r->getFileName(), 2).'/autoload.php';
if (file_exists($file)) {
$requires .= 'require_once '.var_export($file, true).";\n";
}
Expand Down
Expand Up @@ -29,15 +29,15 @@ public function provideTranslationFiles()
{
return array_map(
function ($filePath) { return (array) $filePath; },
glob(\dirname(\dirname(__DIR__)).'/Resources/translations/*.xlf')
glob(\dirname(__DIR__, 2).'/Resources/translations/*.xlf')
);
}

public function testNorwegianAlias()
{
$this->assertFileEquals(
\dirname(\dirname(__DIR__)).'/Resources/translations/security.nb.xlf',
\dirname(\dirname(__DIR__)).'/Resources/translations/security.no.xlf',
\dirname(__DIR__, 2).'/Resources/translations/security.nb.xlf',
\dirname(__DIR__, 2).'/Resources/translations/security.no.xlf',
'The NO locale should be an alias for the NB variant of the Norwegian language.'
);
}
Expand Down
Expand Up @@ -29,15 +29,15 @@ public function provideTranslationFiles()
{
return array_map(
function ($filePath) { return (array) $filePath; },
glob(\dirname(\dirname(__DIR__)).'/Resources/translations/*.xlf')
glob(\dirname(__DIR__, 2).'/Resources/translations/*.xlf')
);
}

public function testNorwegianAlias()
{
$this->assertFileEquals(
\dirname(\dirname(__DIR__)).'/Resources/translations/validators.nb.xlf',
\dirname(\dirname(__DIR__)).'/Resources/translations/validators.no.xlf',
\dirname(__DIR__, 2).'/Resources/translations/validators.nb.xlf',
\dirname(__DIR__, 2).'/Resources/translations/validators.no.xlf',
'The NO locale should be an alias for the NB variant of the Norwegian language.'
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Caster/LinkStub.php
Expand Up @@ -71,7 +71,7 @@ private function getComposerRoot($file, &$inVendor)
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName()));
$v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) {
self::$vendorRoots[] = $v.\DIRECTORY_SEPARATOR;
}
Expand Down

0 comments on commit 2c87f69

Please sign in to comment.