[2.3] Static Code Analysis for Components

This commit is contained in:
Vladimir Reznichenko 2015-03-20 17:17:32 +01:00 committed by Fabien Potencier
parent d5a8a1009b
commit 4abfabf8da
15 changed files with 28 additions and 31 deletions

View File

@ -19,6 +19,6 @@ namespace Symfony\Component\CssSelector\Exception;
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*/
class ExpressionErrorException extends ParseException implements ExceptionInterface
class ExpressionErrorException extends ParseException
{
}

View File

@ -19,6 +19,6 @@ namespace Symfony\Component\CssSelector\Exception;
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*/
class InternalErrorException extends ParseException implements ExceptionInterface
class InternalErrorException extends ParseException
{
}

View File

@ -21,7 +21,7 @@ use Symfony\Component\CssSelector\Parser\Token;
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*/
class SyntaxErrorException extends ParseException implements ExceptionInterface
class SyntaxErrorException extends ParseException
{
/**
* @param string $expectedValue

View File

@ -173,7 +173,7 @@ class GraphvizDumper extends Dumper
foreach ($container->getServiceIds() as $id) {
$service = $container->get($id);
if (in_array($id, array_keys($container->getAliases()))) {
if (array_key_exists($id, $container->getAliases())) {
continue;
}

View File

@ -41,10 +41,9 @@ class Filesystem
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile) && null === parse_url($originFile, PHP_URL_HOST)) {
$doCopy = true;
if (!$override && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
}
if ($doCopy) {
@ -274,7 +273,7 @@ class Filesystem
*/
public function symlink($originDir, $targetDir, $copyOnWindows = false)
{
if (!function_exists('symlink') && $copyOnWindows) {
if ($copyOnWindows && !function_exists('symlink')) {
$this->mirror($originDir, $targetDir);
return;
@ -291,16 +290,14 @@ class Filesystem
}
}
if (!$ok) {
if (true !== @symlink($originDir, $targetDir)) {
$report = error_get_last();
if (is_array($report)) {
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
}
if (!$ok && true !== @symlink($originDir, $targetDir)) {
$report = error_get_last();
if (is_array($report)) {
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
}
throw new IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
}
throw new IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
}
}
@ -339,9 +336,9 @@ class Filesystem
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
// Construct $endPath from traversing to the common path, then to the remaining $endPath
$relativePath = $traverser.(strlen($endPathRemainder) > 0 ? $endPathRemainder.'/' : '');
$relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : '');
return (strlen($relativePath) === 0) ? './' : $relativePath;
return '' === $relativePath ? './' : $relativePath;
}
/**

View File

@ -184,10 +184,10 @@ class NativeRequestHandler implements RequestHandlerInterface
unset($files[$k]);
}
foreach (array_keys($data['name']) as $key) {
foreach ($data['name'] as $key => $name) {
$files[$key] = self::fixPhpFilesArray(array(
'error' => $data['error'][$key],
'name' => $data['name'][$key],
'name' => $name,
'type' => $data['type'][$key],
'tmp_name' => $data['tmp_name'][$key],
'size' => $data['size'][$key],

View File

@ -140,10 +140,10 @@ class FileBag extends ParameterBag
unset($files[$k]);
}
foreach (array_keys($data['name']) as $key) {
foreach ($data['name'] as $key => $name) {
$files[$key] = $this->fixPhpFilesArray(array(
'error' => $data['error'][$key],
'name' => $data['name'][$key],
'name' => $name,
'type' => $data['type'][$key],
'tmp_name' => $data['tmp_name'][$key],
'size' => $data['size'][$key],

View File

@ -1549,7 +1549,7 @@ class Request
foreach (array_keys($languages) as $lang) {
if (strstr($lang, '-')) {
$codes = explode('-', $lang);
if ($codes[0] == 'i') {
if ('i' === $codes[0]) {
// Language not listed in ISO 639 that are not variants
// of any listed language, which can be registered with the
// i-prefix, such as i-cherokee
@ -1558,7 +1558,7 @@ class Request
}
} else {
for ($i = 0, $max = count($codes); $i < $max; $i++) {
if ($i == 0) {
if ($i === 0) {
$lang = strtolower($codes[0]);
} else {
$lang .= '_'.strtoupper($codes[$i]);

View File

@ -75,7 +75,7 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('Can not verify chmod operations on Windows');
}
if (in_array(get_current_user(), array('root'))) {
if ('root' === get_current_user()) {
$this->markTestSkipped('This test will fail if run under superuser');
}

View File

@ -22,7 +22,7 @@ use Symfony\Component\Config\Resource\FileResource;
*
* @api
*/
class CsvFileLoader extends ArrayLoader implements LoaderInterface
class CsvFileLoader extends ArrayLoader
{
private $delimiter = ';';
private $enclosure = '"';

View File

@ -20,7 +20,7 @@ use Symfony\Component\Config\Resource\FileResource;
*
* @author stealth35
*/
class IniFileLoader extends ArrayLoader implements LoaderInterface
class IniFileLoader extends ArrayLoader
{
/**
* {@inheritdoc}

View File

@ -18,7 +18,7 @@ use Symfony\Component\Config\Resource\FileResource;
/**
* @copyright Copyright (c) 2010, Union of RAD http://union-of-rad.org (http://lithify.me/)
*/
class MoFileLoader extends ArrayLoader implements LoaderInterface
class MoFileLoader extends ArrayLoader
{
/**
* Magic used for validating the format of a MO file as well as

View File

@ -22,7 +22,7 @@ use Symfony\Component\Config\Resource\FileResource;
*
* @api
*/
class PhpFileLoader extends ArrayLoader implements LoaderInterface
class PhpFileLoader extends ArrayLoader
{
/**
* {@inheritdoc}

View File

@ -19,7 +19,7 @@ use Symfony\Component\Config\Resource\FileResource;
* @copyright Copyright (c) 2010, Union of RAD http://union-of-rad.org (http://lithify.me/)
* @copyright Copyright (c) 2012, Clemens Tolboom
*/
class PoFileLoader extends ArrayLoader implements LoaderInterface
class PoFileLoader extends ArrayLoader
{
public function load($resource, $locale, $domain = 'messages')
{

View File

@ -24,7 +24,7 @@ use Symfony\Component\Yaml\Exception\ParseException;
*
* @api
*/
class YamlFileLoader extends ArrayLoader implements LoaderInterface
class YamlFileLoader extends ArrayLoader
{
private $yamlParser;