minor #15226 [2.6] Static Code Analysis for Components and Bundles (kalessil)
This PR was squashed before being merged into the 2.6 branch (closes #15226).
Discussion
----------
[2.6] Static Code Analysis for Components and Bundles
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Static Code Analysis with Php Inspections (EA Extended):
- all rules accepted into 2.3
Commits
-------
1dac127
[2.6] Static Code Analysis for Components and Bundles
This commit is contained in:
commit
69fcfa6e6e
@ -95,7 +95,7 @@ EOF
|
||||
);
|
||||
|
||||
foreach ($bundlePaths as $path) {
|
||||
$path = $path.'views';
|
||||
$path .= 'views';
|
||||
if (is_dir($path)) {
|
||||
$this->getContainer()->get('translation.extractor')->extract($path, $extractedCatalogue);
|
||||
}
|
||||
@ -104,7 +104,7 @@ EOF
|
||||
// Load defined messages
|
||||
$currentCatalogue = new MessageCatalogue($locale);
|
||||
foreach ($bundlePaths as $path) {
|
||||
$path = $path.'translations';
|
||||
$path .= 'translations';
|
||||
if (is_dir($path)) {
|
||||
$loader->loadMessages($path, $currentCatalogue);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ EOF
|
||||
$extractor = $this->getContainer()->get('translation.extractor');
|
||||
$extractor->setPrefix($input->getOption('prefix'));
|
||||
foreach ($transPaths as $path) {
|
||||
$path = $path.'views';
|
||||
$path .= 'views';
|
||||
if (is_dir($path)) {
|
||||
$extractor->extract($path, $extractedCatalogue);
|
||||
}
|
||||
@ -119,7 +119,7 @@ EOF
|
||||
$output->writeln('Loading translation files');
|
||||
$loader = $this->getContainer()->get('translation.loader');
|
||||
foreach ($transPaths as $path) {
|
||||
$path = $path.'translations';
|
||||
$path .= 'translations';
|
||||
if (is_dir($path)) {
|
||||
$loader->loadMessages($path, $currentCatalogue);
|
||||
}
|
||||
@ -168,7 +168,7 @@ EOF
|
||||
$output->writeln('Writing files');
|
||||
$bundleTransPath = false;
|
||||
foreach ($transPaths as $path) {
|
||||
$path = $path.'translations';
|
||||
$path .= 'translations';
|
||||
if (is_dir($path)) {
|
||||
$bundleTransPath = $path;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ class TextDescriptor extends Descriptor
|
||||
foreach ($definition->getTag($showTag) as $key => $tag) {
|
||||
$tagValues = array();
|
||||
foreach ($tagsNames as $tagName) {
|
||||
$tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : "";
|
||||
$tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : '';
|
||||
}
|
||||
if (0 === $key) {
|
||||
$table->addRow(array_merge(array($serviceId), $tagValues, array($definition->getClass())));
|
||||
@ -225,10 +225,10 @@ class TextDescriptor extends Descriptor
|
||||
}
|
||||
} elseif ($definition instanceof Alias) {
|
||||
$alias = $definition;
|
||||
$table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, "") : array()));
|
||||
$table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, '') : array()));
|
||||
} else {
|
||||
// we have no information (happens with "service_container")
|
||||
$table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, "") : array()));
|
||||
$table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, '') : array()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ class TextDescriptor extends Descriptor
|
||||
: array();
|
||||
|
||||
$description[] = sprintf('<comment>Service Id</comment> %s', isset($options['id']) ? $options['id'] : '-');
|
||||
$description[] = sprintf('<comment>Class</comment> %s', $definition->getClass() ?: "-");
|
||||
$description[] = sprintf('<comment>Class</comment> %s', $definition->getClass() ?: '-');
|
||||
|
||||
$tags = $definition->getTags();
|
||||
if (count($tags)) {
|
||||
@ -269,7 +269,7 @@ class TextDescriptor extends Descriptor
|
||||
$description[] = sprintf('<comment>Abstract</comment> %s', $definition->isAbstract() ? 'yes' : 'no');
|
||||
|
||||
if ($definition->getFile()) {
|
||||
$description[] = sprintf('<comment>Required File</comment> %s', $definition->getFile() ? $definition->getFile() : '-');
|
||||
$description[] = sprintf('<comment>Required File</comment> %s', $definition->getFile() ?: '-');
|
||||
}
|
||||
|
||||
if ($definition->getFactoryClass()) {
|
||||
|
@ -642,22 +642,22 @@ class FrameworkExtension extends Extension
|
||||
if (class_exists('Symfony\Component\Validator\Validator')) {
|
||||
$r = new \ReflectionClass('Symfony\Component\Validator\Validator');
|
||||
|
||||
$dirs[] = dirname($r->getFilename()).'/Resources/translations';
|
||||
$dirs[] = dirname($r->getFileName()).'/Resources/translations';
|
||||
}
|
||||
if (class_exists('Symfony\Component\Form\Form')) {
|
||||
$r = new \ReflectionClass('Symfony\Component\Form\Form');
|
||||
|
||||
$dirs[] = dirname($r->getFilename()).'/Resources/translations';
|
||||
$dirs[] = dirname($r->getFileName()).'/Resources/translations';
|
||||
}
|
||||
if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) {
|
||||
$r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException');
|
||||
|
||||
$dirs[] = dirname($r->getFilename()).'/../Resources/translations';
|
||||
$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
|
||||
}
|
||||
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
|
||||
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
|
||||
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
if (is_dir($dir = sprintf($overridePath, $bundle))) {
|
||||
@ -775,7 +775,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
||||
$reflection = new \ReflectionClass($bundle);
|
||||
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) {
|
||||
if (is_file($file = dirname($reflection->getFileName()).'/Resources/config/validation.xml')) {
|
||||
$files[] = realpath($file);
|
||||
$container->addResource(new FileResource($file));
|
||||
}
|
||||
@ -790,7 +790,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
||||
$reflection = new \ReflectionClass($bundle);
|
||||
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) {
|
||||
if (is_file($file = dirname($reflection->getFileName()).'/Resources/config/validation.yml')) {
|
||||
$files[] = realpath($file);
|
||||
$container->addResource(new FileResource($file));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class CacheClearCommandTest extends TestCase
|
||||
{
|
||||
$this->fs = new Filesystem();
|
||||
$this->kernel = new TestAppKernel('test', true);
|
||||
$this->rootDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('sf2_cache_');
|
||||
$this->rootDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('sf2_cache_', true);
|
||||
$this->kernel->setRootDir($this->rootDir);
|
||||
$this->fs->mkdir($this->rootDir);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
$this->fs = new Filesystem();
|
||||
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation');
|
||||
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
|
||||
$this->fs->mkdir($this->translationDir.'/Resources/translations');
|
||||
$this->fs->mkdir($this->translationDir.'/Resources/views');
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$data = $this->getDescriptionTestData(ObjectsProvider::getContainerParameter());
|
||||
|
||||
array_push($data[0], array('parameter' => 'database_name'));
|
||||
$data[0][] = array('parameter' => 'database_name');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ class MainConfiguration implements ConfigurationInterface
|
||||
->arrayNode('anonymous')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->scalarNode('key')->defaultValue(uniqid())->end()
|
||||
->scalarNode('key')->defaultValue(uniqid('', true))->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('switch_user')
|
||||
|
@ -54,7 +54,7 @@ class InMemoryFactory implements UserProviderFactoryInterface
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('password')->defaultValue(uniqid())->end()
|
||||
->scalarNode('password')->defaultValue(uniqid('', true))->end()
|
||||
->arrayNode('roles')
|
||||
->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
|
||||
->prototype('scalar')->end()
|
||||
|
@ -18,7 +18,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Lists twig functions, filters, globals and tests present in the current project
|
||||
* Lists twig functions, filters, globals and tests present in the current project.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
@ -111,7 +111,7 @@ EOF
|
||||
if ($type === 'functions' || $type === 'filters') {
|
||||
$args = array();
|
||||
$cb = $entity->getCallable();
|
||||
if (is_null($cb)) {
|
||||
if (null === $cb) {
|
||||
return;
|
||||
}
|
||||
if (is_array($cb)) {
|
||||
|
@ -75,7 +75,7 @@ class TwigExtension extends Extension
|
||||
}
|
||||
|
||||
$reflection = new \ReflectionClass($class);
|
||||
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/views')) {
|
||||
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/views')) {
|
||||
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
|
||||
}
|
||||
}
|
||||
|
@ -156,12 +156,10 @@ class TwigExtensionTest extends TestCase
|
||||
$def = $container->getDefinition('twig.loader.filesystem');
|
||||
$paths = array();
|
||||
foreach ($def->getMethodCalls() as $call) {
|
||||
if ('addPath' === $call[0]) {
|
||||
if (false === strpos($call[1][0], 'Form')) {
|
||||
if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) {
|
||||
$paths[] = $call[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(array(
|
||||
array('path1'),
|
||||
|
@ -196,7 +196,7 @@ class XmlUtils
|
||||
return '0' == $value[0] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
|
||||
case isset($value[1]) && '-' === $value[0] && ctype_digit(substr($value, 1)):
|
||||
$raw = $value;
|
||||
$cast = intval($value);
|
||||
$cast = (int) $value;
|
||||
|
||||
return '0' == $value[1] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
|
||||
case 'true' === $lowercaseValue:
|
||||
|
@ -370,7 +370,7 @@ class ProgressBar
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to overwrite the progressbar, false for new line
|
||||
* Sets whether to overwrite the progressbar, false for new line.
|
||||
*
|
||||
* @param bool $overwrite
|
||||
*/
|
||||
@ -397,8 +397,8 @@ class ProgressBar
|
||||
$this->max = $step;
|
||||
}
|
||||
|
||||
$prevPeriod = intval($this->step / $this->redrawFreq);
|
||||
$currPeriod = intval($step / $this->redrawFreq);
|
||||
$prevPeriod = (int) ($this->step / $this->redrawFreq);
|
||||
$currPeriod = (int) ($step / $this->redrawFreq);
|
||||
$this->step = $step;
|
||||
$this->percent = $this->max ? (float) $this->step / $this->max : 0;
|
||||
if ($prevPeriod !== $currPeriod || $this->max === $step) {
|
||||
|
@ -137,7 +137,8 @@ class ChoiceQuestion extends Question
|
||||
if (empty($choices[$value])) {
|
||||
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
|
||||
}
|
||||
array_push($multiselectChoices, $choices[$value]);
|
||||
|
||||
$multiselectChoices[] = $choices[$value];
|
||||
}
|
||||
|
||||
if ($multiselect) {
|
||||
|
@ -37,6 +37,7 @@ class DebugClassLoader
|
||||
* @param callable|object $classLoader
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @deprecated since 2.5, passing an object is deprecated and support for it will be removed in 3.0
|
||||
*/
|
||||
public function __construct($classLoader)
|
||||
@ -69,7 +70,7 @@ class DebugClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps all autoloaders
|
||||
* Wraps all autoloaders.
|
||||
*/
|
||||
public static function enable()
|
||||
{
|
||||
@ -117,7 +118,7 @@ class DebugClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a file by class name
|
||||
* Finds a file by class name.
|
||||
*
|
||||
* @param string $class A class name to resolve to file
|
||||
*
|
||||
@ -187,7 +188,7 @@ class DebugClassLoader
|
||||
}
|
||||
if (self::$caseCheck && preg_match('#([/\\\\][a-zA-Z_\x7F-\xFF][a-zA-Z0-9_\x7F-\xFF]*)+\.(php|hh)$#D', $file, $tail)) {
|
||||
$tail = $tail[0];
|
||||
$real = $refl->getFilename();
|
||||
$real = $refl->getFileName();
|
||||
|
||||
if (2 === self::$caseCheck) {
|
||||
// realpath() on MacOSX doesn't normalize the case of characters
|
||||
|
@ -112,10 +112,10 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
restore_exception_handler();
|
||||
$this->assertStringStartsWith(__FILE__, $exception->getFile());
|
||||
if (PHP_VERSION_ID < 70000) {
|
||||
$this->assertRegexp('/^Runtime Notice: Declaration/', $exception->getMessage());
|
||||
$this->assertRegExp('/^Runtime Notice: Declaration/', $exception->getMessage());
|
||||
$this->assertEquals(E_STRICT, $exception->getSeverity());
|
||||
} else {
|
||||
$this->assertRegexp('/^Warning: Declaration/', $exception->getMessage());
|
||||
$this->assertRegExp('/^Warning: Declaration/', $exception->getMessage());
|
||||
$this->assertEquals(E_WARNING, $exception->getSeverity());
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
|
@ -77,7 +77,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(E_NOTICE, $exception->getSeverity());
|
||||
$this->assertEquals(__FILE__, $exception->getFile());
|
||||
$this->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
$this->assertArrayHasKey('foobar', $exception->getContext());
|
||||
|
||||
$trace = $exception->getTrace();
|
||||
|
@ -61,7 +61,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
array_map('spl_autoload_register', $autoloaders);
|
||||
}
|
||||
|
||||
$this->assertInstanceof('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
|
||||
$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
|
||||
$this->assertSame($translatedMessage, $exception->getMessage());
|
||||
$this->assertSame($error['type'], $exception->getSeverity());
|
||||
$this->assertSame($error['file'], $exception->getFile());
|
||||
@ -197,6 +197,6 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$handler = new ClassNotFoundFatalErrorHandler();
|
||||
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
|
||||
|
||||
$this->assertInstanceof('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
|
||||
$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class UndefinedFunctionFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$handler = new UndefinedFunctionFatalErrorHandler();
|
||||
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
|
||||
|
||||
$this->assertInstanceof('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception);
|
||||
$this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception);
|
||||
// class names are case insensitive and PHP/HHVM do not return the same
|
||||
$this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage()));
|
||||
$this->assertSame($error['type'], $exception->getSeverity());
|
||||
|
@ -24,7 +24,7 @@ class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$handler = new UndefinedMethodFatalErrorHandler();
|
||||
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
|
||||
|
||||
$this->assertInstanceof('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception);
|
||||
$this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception);
|
||||
$this->assertSame($translatedMessage, $exception->getMessage());
|
||||
$this->assertSame($error['type'], $exception->getSeverity());
|
||||
$this->assertSame($error['file'], $exception->getFile());
|
||||
|
@ -16,7 +16,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
|
||||
private $umask;
|
||||
|
||||
/**
|
||||
* @var string $workspace
|
||||
* @var string
|
||||
*/
|
||||
protected $workspace = null;
|
||||
|
||||
@ -40,7 +40,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
$this->umask = umask(0);
|
||||
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
|
||||
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
|
||||
mkdir($this->workspace, 0777, true);
|
||||
$this->workspace = realpath($this->workspace);
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
private $lockMode = self::LOCK_TRANSACTIONAL;
|
||||
|
||||
/**
|
||||
* It's an array to support multiple reads before closing which is manual, non-standard usage
|
||||
* It's an array to support multiple reads before closing which is manual, non-standard usage.
|
||||
*
|
||||
* @var \PDOStatement[] An array of statements to release advisory locks
|
||||
*/
|
||||
@ -483,7 +483,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
if ('sqlite' === $this->driver) {
|
||||
$this->pdo->exec('ROLLBACK');
|
||||
} else {
|
||||
$this->pdo->rollback();
|
||||
$this->pdo->rollBack();
|
||||
}
|
||||
$this->inTransaction = false;
|
||||
}
|
||||
@ -680,7 +680,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a PDO instance
|
||||
* Return a PDO instance.
|
||||
*
|
||||
* @return \PDO
|
||||
*/
|
||||
|
@ -138,7 +138,7 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSerialCorrelation($secureRandom)
|
||||
{
|
||||
$shift = rand(1, 5000);
|
||||
$shift = mt_rand(1, 5000);
|
||||
$b = $this->getBitSequence($secureRandom, 20000);
|
||||
|
||||
$Z = 0;
|
||||
|
@ -20,7 +20,7 @@ use Symfony\Component\Config\Resource\FileResource;
|
||||
*
|
||||
* @author singles
|
||||
*/
|
||||
class JsonFileLoader extends ArrayLoader implements LoaderInterface
|
||||
class JsonFileLoader extends ArrayLoader
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -502,7 +502,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetMessages($resources, $locale, $expected)
|
||||
{
|
||||
$locales = array_keys($resources);
|
||||
$_locale = !is_null($locale) ? $locale : reset($locales);
|
||||
$_locale = null !== $locale ? $locale : reset($locales);
|
||||
$locales = array_slice($locales, 0, array_search($_locale, $locales));
|
||||
|
||||
$translator = new Translator($_locale, new MessageSelector());
|
||||
|
Reference in New Issue
Block a user