bug #21803 [master] Fix issues reported by static analyse (romainneutron)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[master] Fix issues reported by static analyse

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Follow-up #21802

Commits
-------

671694d [master] Fix issues reported by static analyse
This commit is contained in:
Nicolas Grekas 2017-02-28 16:52:13 +01:00
commit 3729a157b9
12 changed files with 28 additions and 29 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;

View File

@ -11,7 +11,7 @@
namespace Symfony\Bundle\TwigBundle; 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 Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;

View File

@ -15,6 +15,7 @@ use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\CacheException as Psr6CacheException; use Psr\Cache\CacheException as Psr6CacheException;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\CacheException as SimpleCacheException; use Psr\SimpleCache\CacheException as SimpleCacheException;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException; use Symfony\Component\Cache\Exception\InvalidArgumentException;
@ -30,7 +31,7 @@ class Psr6Cache implements CacheInterface
{ {
$this->pool = $pool; $this->pool = $pool;
if ($pool instanceof Adapter\AdapterInterface) { if ($pool instanceof AbstractAdapter) {
$this->createCacheItem = \Closure::bind( $this->createCacheItem = \Closure::bind(
function ($key, $value, $allowInt = false) { function ($key, $value, $allowInt = false) {
if ($allowInt && is_int($key)) { if ($allowInt && is_int($key)) {
@ -38,14 +39,12 @@ class Psr6Cache implements CacheInterface
} else { } else {
CacheItem::validateKey($key); CacheItem::validateKey($key);
} }
$item = new CacheItem(); $f = $this->createCacheItem;
$item->key = $key;
$item->value = $value;
return $item; return $f($key, $value, false);
}, },
null, $pool,
CacheItem::class AbstractAdapter::class
); );
} }
} }

View File

@ -144,7 +144,7 @@ abstract class FileLoader extends Loader
} }
if (!class_exists(Finder::class)) { 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(); $finder = new Finder();

View File

@ -70,7 +70,7 @@ abstract class Helper implements HelperInterface
public static function substr($string, $from, $length = null) public static function substr($string, $from, $length = null)
{ {
if (false === $encoding = mb_detect_encoding($string, null, true)) { if (false === $encoding = mb_detect_encoding($string, null, true)) {
return substr($string); return substr($string, $from, $length);
} }
return mb_substr($string, $from, $length, $encoding); return mb_substr($string, $from, $length, $encoding);

View File

@ -114,7 +114,7 @@ class AutowirePass extends AbstractRecursivePass
if ($constructor = $reflectionClass->getConstructor()) { if ($constructor = $reflectionClass->getConstructor()) {
array_unshift($methodCalls, array($constructor->name, $value->getArguments())); array_unshift($methodCalls, array($constructor->name, $value->getArguments()));
} elseif ($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); $methodCalls = $this->autowireCalls($reflectionClass, $methodCalls, $autowiredMethods);

View File

@ -94,7 +94,7 @@ class ServiceReferenceGraph
if (__CLASS__ !== get_class($this)) { if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__); $r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) { 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; $lazy = false;

View File

@ -117,6 +117,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/ */
private $vendors; private $vendors;
/**
* @var \ReflectionClass[] a list of class reflectors
*/
private $classReflectors;
/** /**
* Sets the track resources flag. * Sets the track resources flag.
* *

View File

@ -1,17 +1,21 @@
<?php <?php
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ServiceLocator;
/** /**
* ProjectServiceContainer. * ProjectServiceContainer.
* *
* This class has been auto-generated * This class has been auto-generated
* by the Symfony Dependency Injection Component. * by the Symfony Dependency Injection Component.
*
* @final since Symfony 3.3
*/ */
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {

View File

@ -151,7 +151,7 @@ class Process implements \IteratorAggregate
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.'); throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
} }
$this->setCommandline($commandline); $this->setCommandLine($commandline);
$this->cwd = $cwd; $this->cwd = $cwd;
// on Windows, if the cwd changed via chdir(), proc_open defaults to the dir where PHP was started // 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; $env = null;
} elseif (null !== $env) { } 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) { if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
$this->options['bypass_shell'] = true; $this->options['bypass_shell'] = true;
@ -1291,7 +1291,7 @@ class Process implements \IteratorAggregate
public function inheritEnvironmentVariables($inheritEnv = true) public function inheritEnvironmentVariables($inheritEnv = true)
{ {
if (!$inheritEnv) { 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; $this->inheritEnv = (bool) $inheritEnv;

View File

@ -185,7 +185,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
if (__CLASS__ !== get_class($this)) { if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__); $r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) { 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)) { if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__); $r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) { 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)) { if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__); $r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) { 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)) { if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__); $r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) { 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);
} }
} }

View File

@ -26,7 +26,6 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/ */
class XliffLintCommand extends Command class XliffLintCommand extends Command
{ {
private $parser;
private $format; private $format;
private $displayCorrectFiles; private $displayCorrectFiles;
private $directoryIteratorProvider; private $directoryIteratorProvider;
@ -214,15 +213,6 @@ EOF
return $inputs; return $inputs;
} }
private function getParser()
{
if (!$this->parser) {
$this->parser = new Parser();
}
return $this->parser;
}
private function getDirectoryIterator($directory) private function getDirectoryIterator($directory)
{ {
$default = function ($directory) { $default = function ($directory) {