From aa5e616511f96c2542faede5e4c3dbb7e76ad8b9 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sun, 21 Jun 2015 07:33:01 +0200 Subject: [PATCH] [2.3] Static Code Analysis for Components --- src/Symfony/Component/BrowserKit/Cookie.php | 2 +- .../ClassLoader/Tests/ClassMapGeneratorTest.php | 2 +- .../Config/Tests/Resource/DirectoryResourceTest.php | 2 +- .../Component/Config/Tests/Resource/FileResourceTest.php | 2 +- src/Symfony/Component/Console/Input/ArgvInput.php | 2 +- .../Component/Filesystem/Tests/FilesystemTest.php | 2 +- .../Extension/Core/Type/ChoiceTypePerformanceTest.php | 2 +- src/Symfony/Component/HttpFoundation/Request.php | 9 ++++++++- .../Tests/Data/Bundle/Writer/JsonBundleWriterTest.php | 2 +- .../Tests/Data/Bundle/Writer/PhpBundleWriterTest.php | 2 +- .../Tests/Data/Bundle/Writer/TextBundleWriterTest.php | 2 +- .../Component/Intl/Tests/Data/Util/LocaleScannerTest.php | 2 +- .../Templating/Tests/Loader/CacheLoaderTest.php | 2 +- 13 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index 424f78bab4..18b9324403 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -77,7 +77,7 @@ class Cookie if (null !== $expires) { $timestampAsDateTime = \DateTime::createFromFormat('U', $expires); if (false === $timestampAsDateTime) { - throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $expires); + throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires)); } $this->expires = $timestampAsDateTime->getTimestamp(); diff --git a/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php b/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php index 88099258ec..29c3288347 100644 --- a/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php +++ b/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php @@ -22,7 +22,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase public function prepare_workspace() { - $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); } diff --git a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php index d78e0cf7f6..226e2807dc 100644 --- a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php @@ -69,7 +69,7 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed'); $this->assertFalse($resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated'); - $resource = new DirectoryResource('/____foo/foobar'.rand(1, 999999)); + $resource = new DirectoryResource('/____foo/foobar'.mt_rand(1, 999999)); $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist'); } diff --git a/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php index d152806d0c..db85cf7bd0 100644 --- a/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php @@ -48,7 +48,7 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed'); $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated'); - $resource = new FileResource('/____foo/foobar'.rand(1, 999999)); + $resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999)); $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist'); } diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 97b0cfc05d..43cbe725fb 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -221,7 +221,7 @@ class ArgvInput extends Input } if (null !== $value && !$option->acceptValue()) { - throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value)); + throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); } if (null === $value && $option->acceptValue() && count($this->parsed)) { diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 62dfd9ad91..40b05b88bb 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -51,7 +51,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase { $this->umask = umask(0); $this->filesystem = new Filesystem(); - $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); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php index 0685946fc1..83430d935c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php @@ -30,7 +30,7 @@ class ChoiceTypePerformanceTest extends FormPerformanceTestCase $choices = range(1, 300); for ($i = 0; $i < 100; ++$i) { - $this->factory->create('choice', rand(1, 400), array( + $this->factory->create('choice', mt_rand(1, 400), array( 'choices' => $choices, )); } diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 9e94407ec5..424a2ed09f 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -476,10 +476,17 @@ class Request */ public function __toString() { + $content = ''; + try { + $content = $this->getContent(); + } catch (\LogicException $e) { + trigger_error($e->getMessage(), E_USER_ERROR); + } + return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". $this->headers."\r\n". - $this->getContent(); + $content; } /** diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php index 69575289cd..c449cf82db 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php @@ -39,7 +39,7 @@ class JsonBundleWriterTest extends \PHPUnit_Framework_TestCase } $this->writer = new JsonBundleWriter(); - $this->directory = sys_get_temp_dir().'/JsonBundleWriterTest/'.rand(1000, 9999); + $this->directory = sys_get_temp_dir().'/JsonBundleWriterTest/'.mt_rand(1000, 9999); $this->filesystem = new Filesystem(); $this->filesystem->mkdir($this->directory); diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php index ca3fd71238..a855fbffef 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php @@ -35,7 +35,7 @@ class PhpBundleWriterTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->writer = new PhpBundleWriter(); - $this->directory = sys_get_temp_dir().'/PhpBundleWriterTest/'.rand(1000, 9999); + $this->directory = sys_get_temp_dir().'/PhpBundleWriterTest/'.mt_rand(1000, 9999); $this->filesystem = new Filesystem(); $this->filesystem->mkdir($this->directory); diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/TextBundleWriterTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/TextBundleWriterTest.php index 1252be82d1..197a4e1fc0 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/TextBundleWriterTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/TextBundleWriterTest.php @@ -36,7 +36,7 @@ class TextBundleWriterTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->writer = new TextBundleWriter(); - $this->directory = sys_get_temp_dir().'/TextBundleWriterTest/'.rand(1000, 9999); + $this->directory = sys_get_temp_dir().'/TextBundleWriterTest/'.mt_rand(1000, 9999); $this->filesystem = new Filesystem(); $this->filesystem->mkdir($this->directory); diff --git a/src/Symfony/Component/Intl/Tests/Data/Util/LocaleScannerTest.php b/src/Symfony/Component/Intl/Tests/Data/Util/LocaleScannerTest.php index 34d9713481..7c37c80720 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Util/LocaleScannerTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Util/LocaleScannerTest.php @@ -33,7 +33,7 @@ class LocaleScannerTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->directory = sys_get_temp_dir().'/LocaleScannerTest/'.rand(1000, 9999); + $this->directory = sys_get_temp_dir().'/LocaleScannerTest/'.mt_rand(1000, 9999); $this->filesystem = new Filesystem(); $this->scanner = new LocaleScanner(); diff --git a/src/Symfony/Component/Templating/Tests/Loader/CacheLoaderTest.php b/src/Symfony/Component/Templating/Tests/Loader/CacheLoaderTest.php index 1eabaeb3c8..c82a71f906 100644 --- a/src/Symfony/Component/Templating/Tests/Loader/CacheLoaderTest.php +++ b/src/Symfony/Component/Templating/Tests/Loader/CacheLoaderTest.php @@ -28,7 +28,7 @@ class CacheLoaderTest extends \PHPUnit_Framework_TestCase public function testLoad() { - $dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.rand(111111, 999999); + $dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.mt_rand(111111, 999999); mkdir($dir, 0777, true); $loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir); $loader->setDebugger($debugger = new \Symfony\Component\Templating\Tests\Fixtures\ProjectTemplateDebugger());