From 671694d0d6b100ba504e6c973d82620cc39eb525 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 28 Feb 2017 15:54:44 +0100 Subject: [PATCH] [master] Fix issues reported by static analyse --- .../Compiler/CachePoolClearerPass.php | 1 + .../TwigBundle/ContainerAwareRuntimeLoader.php | 2 +- src/Symfony/Component/Cache/Simple/Psr6Cache.php | 13 ++++++------- src/Symfony/Component/Config/Loader/FileLoader.php | 2 +- src/Symfony/Component/Console/Helper/Helper.php | 2 +- .../DependencyInjection/Compiler/AutowirePass.php | 2 +- .../Compiler/ServiceReferenceGraph.php | 2 +- .../DependencyInjection/ContainerBuilder.php | 5 +++++ .../DependencyInjection/Loader/YamlFileLoader.php | 1 + .../Tests/Fixtures/php/services_private_frozen.php | 4 ++++ src/Symfony/Component/Process/Process.php | 6 +++--- src/Symfony/Component/Serializer/Serializer.php | 8 ++++---- .../Translation/Command/XliffLintCommand.php | 10 ---------- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolClearerPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolClearerPass.php index 3cb3aeb894..591d03c58a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolClearerPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolClearerPass.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; +use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; diff --git a/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php b/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php index eaa4d698bf..e2988f3aae 100644 --- a/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php +++ b/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\TwigBundle; -@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig_ContainerRuntimeLoader class instead.'), ContainerAwareRuntimeLoader::class); +@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig_ContainerRuntimeLoader class instead.', ContainerAwareRuntimeLoader::class), E_USER_DEPRECATED); use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/src/Symfony/Component/Cache/Simple/Psr6Cache.php b/src/Symfony/Component/Cache/Simple/Psr6Cache.php index d23af54069..55fa98da12 100644 --- a/src/Symfony/Component/Cache/Simple/Psr6Cache.php +++ b/src/Symfony/Component/Cache/Simple/Psr6Cache.php @@ -15,6 +15,7 @@ use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheException as Psr6CacheException; use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheException as SimpleCacheException; +use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\Exception\InvalidArgumentException; @@ -30,7 +31,7 @@ class Psr6Cache implements CacheInterface { $this->pool = $pool; - if ($pool instanceof Adapter\AdapterInterface) { + if ($pool instanceof AbstractAdapter) { $this->createCacheItem = \Closure::bind( function ($key, $value, $allowInt = false) { if ($allowInt && is_int($key)) { @@ -38,14 +39,12 @@ class Psr6Cache implements CacheInterface } else { CacheItem::validateKey($key); } - $item = new CacheItem(); - $item->key = $key; - $item->value = $value; + $f = $this->createCacheItem; - return $item; + return $f($key, $value, false); }, - null, - CacheItem::class + $pool, + AbstractAdapter::class ); } } diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php index 059186867b..f54b6f8cda 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -144,7 +144,7 @@ abstract class FileLoader extends Loader } if (!class_exists(Finder::class)) { - throw new LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $resource)); + throw new \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $resource)); } $finder = new Finder(); diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php index e8d39b6ff8..1124f80ef3 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -70,7 +70,7 @@ abstract class Helper implements HelperInterface public static function substr($string, $from, $length = null) { if (false === $encoding = mb_detect_encoding($string, null, true)) { - return substr($string); + return substr($string, $from, $length); } return mb_substr($string, $from, $length, $encoding); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index ec378d1318..075356bcbc 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -113,7 +113,7 @@ class AutowirePass extends AbstractRecursivePass if ($constructor = $reflectionClass->getConstructor()) { array_unshift($methodCalls, array($constructor->name, $value->getArguments())); } elseif ($value->getArguments()) { - throw new RuntimeException(sprintf('Cannot autowire service "%s": class %s has no constructor but arguments are defined.', $this->currentId, $reflectionClass->name, $method)); + throw new RuntimeException(sprintf('Cannot autowire service "%s": class %s has no constructor but arguments are defined.', $this->currentId, $reflectionClass->name)); } $methodCalls = $this->autowireCalls($reflectionClass, $methodCalls, $autowiredMethods); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php index 4ab49d21cc..35733c72d0 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php @@ -94,7 +94,7 @@ class ServiceReferenceGraph if (__CLASS__ !== get_class($this)) { $r = new \ReflectionMethod($this, __FUNCTION__); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a 6th `$lazy = false` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('Method %s() will have a 6th `$lazy = false` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); } } $lazy = false; diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index bdbdd3a878..679f931e14 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -117,6 +117,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface */ private $vendors; + /** + * @var \ReflectionClass[] a list of class reflectors + */ + private $classReflectors; + /** * Sets the track resources flag. * diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 6ad27499e7..15e78fcb3f 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php index f14141b8d1..f66693a105 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php @@ -1,17 +1,21 @@ setCommandline($commandline); + $this->setCommandLine($commandline); $this->cwd = $cwd; // on Windows, if the cwd changed via chdir(), proc_open defaults to the dir where PHP was started @@ -309,7 +309,7 @@ class Process implements \IteratorAggregate } $env = null; } elseif (null !== $env) { - @trigger_error(sprintf('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED); } if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) { $this->options['bypass_shell'] = true; @@ -1291,7 +1291,7 @@ class Process implements \IteratorAggregate public function inheritEnvironmentVariables($inheritEnv = true) { if (!$inheritEnv) { - @trigger_error(sprintf('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED); } $this->inheritEnv = (bool) $inheritEnv; diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 5c20bf63e6..36752465ac 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -185,7 +185,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz if (__CLASS__ !== get_class($this)) { $r = new \ReflectionMethod($this, __FUNCTION__); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a third `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('Method %s() will have a third `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); } } @@ -206,7 +206,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz if (__CLASS__ !== get_class($this)) { $r = new \ReflectionMethod($this, __FUNCTION__); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a fourth `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('Method %s() will have a fourth `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); } } @@ -306,7 +306,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz if (__CLASS__ !== get_class($this)) { $r = new \ReflectionMethod($this, __FUNCTION__); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); } } @@ -327,7 +327,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz if (__CLASS__ !== get_class($this)) { $r = new \ReflectionMethod($this, __FUNCTION__); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); } } diff --git a/src/Symfony/Component/Translation/Command/XliffLintCommand.php b/src/Symfony/Component/Translation/Command/XliffLintCommand.php index 7707295fde..80d8bb25dc 100644 --- a/src/Symfony/Component/Translation/Command/XliffLintCommand.php +++ b/src/Symfony/Component/Translation/Command/XliffLintCommand.php @@ -26,7 +26,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; */ class XliffLintCommand extends Command { - private $parser; private $format; private $displayCorrectFiles; private $directoryIteratorProvider; @@ -214,15 +213,6 @@ EOF return $inputs; } - private function getParser() - { - if (!$this->parser) { - $this->parser = new Parser(); - } - - return $this->parser; - } - private function getDirectoryIterator($directory) { $default = function ($directory) {