From 3af3dd1d96b5680e24b166e1374ec4ad0d41ca3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Thu, 8 Oct 2020 16:17:51 +0200 Subject: [PATCH] Add native_constant_invocation cs rule (#1271) * Add native_constant_invocation cs rule * Adapt code --- .php_cs.dist | 1 + Command/BaseBootstrapSymlinkCommand.php | 14 +++++++------- Command/InstallFontCommand.php | 10 +++++----- Composer/ScriptHandler.php | 10 +++++----- DependencyInjection/MopaBootstrapExtension.php | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 3188b187c..b918a47f0 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -14,6 +14,7 @@ return PhpCsFixer\Config::create() '@Symfony' => true, 'header_comment' => ['header' => $header], 'full_opening_tag' => false, + 'native_constant_invocation' => true, 'native_function_invocation' => true, 'yoda_style' => false, 'array_syntax' => ['syntax' => 'short'], diff --git a/Command/BaseBootstrapSymlinkCommand.php b/Command/BaseBootstrapSymlinkCommand.php index 4a02f7a53..145ac3571 100644 --- a/Command/BaseBootstrapSymlinkCommand.php +++ b/Command/BaseBootstrapSymlinkCommand.php @@ -74,7 +74,7 @@ public static function checkSymlink($symlinkTarget, $symlinkName, $forceSymlink if (!$forceSymlink) { throw new \Exception(\sprintf('Symlink "%s" points to "%s" instead of "%s"', $symlinkName, $linkTarget, $symlinkTarget)); } - if (\strtoupper(\substr(PHP_OS, 0, 3)) === 'WIN' && \is_dir($linkTarget)) { + if (\strtoupper(\substr(\PHP_OS, 0, 3)) === 'WIN' && \is_dir($linkTarget)) { \rmdir($symlinkName); } else { \unlink($symlinkName); @@ -126,7 +126,7 @@ public static function createMirror($symlinkTarget, $symlinkName) $filesystem = new Filesystem(); $filesystem->mkdir($symlinkName); $filesystem->mirror( - $symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget, + $symlinkName.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.$symlinkTarget, $symlinkName, null, ['copy_on_windows' => true, 'delete' => true, 'override' => true] @@ -169,8 +169,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } elseif (false !== $composer = ComposerAdapter::getComposer($input, $output)) { $cmanager = new ComposerPathFinder($composer); $options = [ - 'targetSuffix' => DIRECTORY_SEPARATOR.$this->bootstrapInstallPath.static::$targetSuffix, - 'sourcePrefix' => '..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR, + 'targetSuffix' => \DIRECTORY_SEPARATOR.$this->bootstrapInstallPath.static::$targetSuffix, + 'sourcePrefix' => '..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR, ]; list($symlinkTarget, $symlinkName) = $cmanager->getSymlinkFromComposer( self::$mopaBootstrapBundleName, @@ -184,7 +184,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } // Automatically detect if on Win XP where symlink will allways fail - if ($input->getOption('no-symlink') || PHP_OS == 'WINNT') { + if ($input->getOption('no-symlink') || \PHP_OS == 'WINNT') { $this->output->write('Checking destination'); if (true === self::checkSymlink($symlinkTarget, $symlinkName)) { @@ -192,7 +192,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $this->output->writeln(' ... not existing'); $this->output->writeln(\sprintf('Mirroring to: %s', $symlinkName)); - $this->output->write(\sprintf('from target: %s', \realpath($symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget))); + $this->output->write(\sprintf('from target: %s', \realpath($symlinkName.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.$symlinkTarget))); self::createMirror($symlinkTarget, $symlinkName); } } else { @@ -231,7 +231,7 @@ protected function getBootstrapPathsFromUser() throw new \Exception('Target path '.$symlinkTarget.'is not a directory!'); } } else { - $symlinkTarget = $symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget; + $symlinkTarget = $symlinkName.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.$symlinkTarget; } if (!\is_dir($symlinkTarget)) { diff --git a/Command/InstallFontCommand.php b/Command/InstallFontCommand.php index 388d1214e..2422df8ab 100644 --- a/Command/InstallFontCommand.php +++ b/Command/InstallFontCommand.php @@ -77,12 +77,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $finder = new Finder(); if (Kernel::VERSION_ID >= 40200) { - $webPath = $this->kernel->getProjectDir().DIRECTORY_SEPARATOR.'web'; + $webPath = $this->kernel->getProjectDir().\DIRECTORY_SEPARATOR.'web'; } else { - $webPath = $this->kernel->getRootDir().DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'web'; + $webPath = $this->kernel->getRootDir().\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'web'; } - $iconWebPath = $webPath.DIRECTORY_SEPARATOR.'fonts'; + $iconWebPath = $webPath.\DIRECTORY_SEPARATOR.'fonts'; $fs = new Filesystem(); @@ -98,12 +98,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $bsbPath = $composer->getInstallationManager()->getInstallPath($sourcePackage); - $iconSetPath = $bsbPath.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.self::$iconSetsPaths[$this->iconSet]; + $iconSetPath = $bsbPath.\DIRECTORY_SEPARATOR.'Resources'.\DIRECTORY_SEPARATOR.'public'.\DIRECTORY_SEPARATOR.self::$iconSetsPaths[$this->iconSet]; $finder->files()->in($iconSetPath); foreach ($finder as $file) { - $fs->copy($file->getRealpath(), $iconWebPath.DIRECTORY_SEPARATOR.$file->getRelativePathname()); + $fs->copy($file->getRealpath(), $iconWebPath.\DIRECTORY_SEPARATOR.$file->getRelativePathname()); } $output->writeln('Font: '.$this->iconSet.' Installed... OK'); diff --git a/Composer/ScriptHandler.php b/Composer/ScriptHandler.php index fbdea3f04..0401bc00f 100644 --- a/Composer/ScriptHandler.php +++ b/Composer/ScriptHandler.php @@ -28,7 +28,7 @@ public static function postInstallSymlinkTwitterBootstrap(Event $event) $cmanager = new ComposerPathFinder($composer); $options = [ 'targetSuffix' => self::getTargetSuffix(), - 'sourcePrefix' => '..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR, + 'sourcePrefix' => '..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR, ]; list($symlinkTarget, $symlinkName) = $cmanager->getSymlinkFromComposer( BootstrapSymlinkLessCommand::$mopaBootstrapBundleName, @@ -51,7 +51,7 @@ public static function postInstallMirrorTwitterBootstrap(Event $event) $cmanager = new ComposerPathFinder($composer); $options = [ 'targetSuffix' => self::getTargetSuffix(), - 'sourcePrefix' => '..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR, + 'sourcePrefix' => '..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR, ]; list($symlinkTarget, $symlinkName) = $cmanager->getSymlinkFromComposer( BootstrapSymlinkLessCommand::$mopaBootstrapBundleName, @@ -74,7 +74,7 @@ public static function postInstallSymlinkTwitterBootstrapSass(Event $event) $cmanager = new ComposerPathFinder($composer); $options = [ 'targetSuffix' => self::getTargetSuffix('-sass'), - 'sourcePrefix' => '..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR, + 'sourcePrefix' => '..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR, ]; list($symlinkTarget, $symlinkName) = $cmanager->getSymlinkFromComposer( BootstrapSymlinkSassCommand::$mopaBootstrapBundleName, @@ -97,7 +97,7 @@ public static function postInstallMirrorTwitterBootstrapSass(Event $event) $cmanager = new ComposerPathFinder($composer); $options = [ 'targetSuffix' => self::getTargetSuffix('-sass'), - 'sourcePrefix' => '..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR, + 'sourcePrefix' => '..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR, ]; list($symlinkTarget, $symlinkName) = $cmanager->getSymlinkFromComposer( BootstrapSymlinkSassCommand::$mopaBootstrapBundleName, @@ -115,6 +115,6 @@ public static function postInstallMirrorTwitterBootstrapSass(Event $event) protected static function getTargetSuffix($end = '') { - return DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'bootstrap'.$end; + return \DIRECTORY_SEPARATOR.'Resources'.\DIRECTORY_SEPARATOR.'public'.\DIRECTORY_SEPARATOR.'bootstrap'.$end; } } diff --git a/DependencyInjection/MopaBootstrapExtension.php b/DependencyInjection/MopaBootstrapExtension.php index a68a91788..6ec34ebcf 100644 --- a/DependencyInjection/MopaBootstrapExtension.php +++ b/DependencyInjection/MopaBootstrapExtension.php @@ -78,7 +78,7 @@ public function load(array $configs, ContainerBuilder $container) if ($this->isConfigEnabled($container, $config['menu']) || $this->isConfigEnabled($container, $config['navbar'])) { // @deprecated: remove this BC layer if ($this->isConfigEnabled($container, $config['navbar'])) { - \trigger_error(\sprintf('mopa_bootstrap.navbar is deprecated. Use mopa_bootstrap.menu.'), E_USER_DEPRECATED); + \trigger_error(\sprintf('mopa_bootstrap.navbar is deprecated. Use mopa_bootstrap.menu.'), \E_USER_DEPRECATED); } $loader->load('menu.xml'); $this->remapParameters($container, 'mopa_bootstrap.menu', $config['menu']);