8000 minor #21537 Static code analysis with Php Inspections (EA Extended) … · symfony/symfony@a5c099c · GitHub
[go: up one dir, main page]

Skip to content

Commit a5c099c

Browse files
committed
minor #21537 Static code analysis with Php Inspections (EA Extended) (kalessil)
This PR was squashed before being merged into the 2.7 branch (closes #21537). Discussion ---------- Static code analysis with Php Inspections (EA Extended) | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | -- | License | MIT | Doc PR | -- - Unnecessary proxy methods and methods duplicating parents ones removed; - Type casings instead of PHP4 functions; - Usage of copy instead of file combining file get/put contents; - One time use variables cleaned up; - Superfluous functions calls in loop termination conditions fixed; Commits ------- 3feeca7 Static code analysis with Php Inspections (EA Extended)
2 parents 38490da + 3feeca7 commit a5c099c

File tree

15 files changed

+19
-54
lines changed

15 files changed

+19
-54
lines changed

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function fileExcerpt($file, $line)
138138
$code = @highlight_file($file, true);
139139
// remove main code/span tags
140140
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
141-
$content = preg_split('#<br />#', $code);
141+
$content = explode('<br />', $code);
142142

143143
$lines = array();
144144
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; ++$i) {

src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ protected function getFragmentHandler($return)
6262

6363
$context->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
6464

65-
$renderer = new FragmentHandler(array($strategy), false, $context);
66-
67-
return $renderer;
65+
return new FragmentHandler(array($strategy), false, $context);
6866
}
6967

7068
protected function renderTemplate(FragmentHandler $renderer, $templa A3DB te = '{{ render("foo") }}')

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function fileExcerpt($file, $line)
132132
$code = @highlight_file($file, true);
133133
// remove main code/span tags
134134
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
135-
$content = preg_split('#<br />#', $code);
135+
$content = explode('<br />', $code);
136136

137137
$lines = array();
138138
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; ++$i) {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@
4646

4747
<?php echo $view['translator']->trans('typecast', ['a' => (int) '123'], 'not_messages'); ?>
4848
<?php echo $view['translator']->transChoice('msg1', 10 + 1, [], 'not_messages'); ?>
49-
<?php echo $view['translator']->transChoice('msg2', intval(4.5), [], 'not_messages'); ?>
49+
<?php echo $view['translator']->transChoice('msg2', ceil(4.5), [], 'not_messages'); ?>

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimpleFormFactory.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,4 @@ protected function createListener($container, $id, $config, $userProvider)
7777

7878
return $listenerId;
7979
}
80-
81-
protected function createEntryPoint($container, $id, $config, $defaultEntryPoint)
82-
{
83-
$entryPointId = 'security.authentication.form_entry_point.'.$id;
84-
$container
85-
->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.form_entry_point'))
86-
->addArgument(new Reference('security.http_utils'))
87-
->addArgument($config['login_path'])
88-
->addArgument($config['use_forward'])
89-
;
90-
91-
return $entryPointId;
92-
}
9380
}

src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testCrossCheck($fixture, $type)
3636

3737
$tmp = tempnam(sys_get_temp_dir(), 'sf');
3838

39-
file_put_contents($tmp, file_get_contents(self::$fixturesPath.'/'.$type.'/'.$fixture));
39+
copy(self::$fixturesPath.'/'.$type.'/'.$fixture, $tmp);
4040

4141
$container1 = new ContainerBuilder();
4242
$loader1 = new $loaderClass($container1, new FileLocator());

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function setContentDisposition($disposition, $filename = '', $filenameFal
164164
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
165165
$encoding = mb_detect_encoding($filename, null, true);
166166

167-
for ($i = 0; $i < mb_strlen($filename, $encoding); ++$i) {
167+
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
168168
$char = mb_substr($filename, $i, 1, $encoding);
169169

170170
if ('%' === $char || ord($char) < 32 || ord($char) > 126) {

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testRead()
108108

109109
if (phpversion('mongodb')) {
110110
$that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$that->options['expiry_field']]['$gte']);
111-
$that->assertGreaterThanOrEqual(round(intval((string) $criteria[$that->options['expiry_field']]['$gte']) / 1000), $testTimeout);
111+
$that->assertGreaterThanOrEqual(round(((int) $criteria[$that->options['expiry_field']]['$gte']) / 1000), $testTimeout);
112112
} else {
113113
$that->assertInstanceOf('MongoDate', $criteria[$that->options['expiry_field']]['$gte']);
114114
$that->assertGreaterThanOrEqual($criteria[$that->options['expiry_field']]['$gte']->sec, $testTimeout);
@@ -167,7 +167,7 @@ public function testWrite()
167167
$that->assertEquals('bar', $data[$that->options['data_field']]->getData());
168168
$that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$that->options['time_field']]);
169169
$that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$that->options['expiry_field']]);
170-
$that->assertGreaterThanOrEqual($expectedExpiry, round(intval((string) $data[$that->options['expiry_field']]) / 1000));
170+
$that->assertGreaterThanOrEqual($expectedExpiry, round(((int) $data[$that->options['expiry_field']]) / 1000));
171171
} else {
172172
$that->assertEquals('bar', $data[$that->options['data_field']]->bin);
173173
$that->assertInstanceOf('MongoDate', $data[$that->options['time_field']]);
@@ -293,7 +293,7 @@ public function testGc()
293293
->will($this->returnCallback(function ($criteria) use ($that) {
294294
if (phpversion('mongodb')) {
295295
$that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$that->options['expiry_field']]['$lt']);
296-
$that->assertGreaterThanOrEqual(time() - 1, round(intval((string) $criteria[$that->options['expiry_field']]['$lt']) / 1000));
296+
$that->assertGreaterThanOrEqual(time() - 1, round(((int) $criteria[$that->options['expiry_field']]['$lt']) / 1000));
297297
} else {
298298
$that->assertInstanceOf('MongoDate', $criteria[$that->options['expiry_field']]['$lt']);
299299
$that->assertGreaterThanOrEqual(time() - 1, $criteria[$that->options['expiry_field']]['$lt']->sec);

src/Symfony/Component/HttpKernel/Client.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* Client simulates a browser and makes requests to a Kernel object.
2626
*
2727
* @author Fabien Potencier <fabien@symfony.com>
28+
*
29+
* @method Request|null getRequest() A Request instance
30+
* @method Response|null getResponse() A Response instance
2831
*/
2932
class Client extends BaseClient
3033
{
@@ -47,26 +50,6 @@ public function __construct(HttpKernelInterface $kernel, array $server = array()
4750
parent::__construct($server, $history, $cookieJar);
4851
}
4952

50-
/**
51-
* {@inheritdoc}
52-
*
53-
* @return Request|null A Request instance
54-
*/
55-
public function getRequest()
56-
{
57-
return parent::getRequest();
58-
}
59-
60-
/**
61-
* {@inheritdoc}
62-
*
63-
* @return Response|null A Response instance
64-
*/
65-
public function getResponse()
66-
{
67-
return parent::getResponse();
68-
}
69-
7053
/**
7154
* Makes a request.
7255
*

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function exportValue($value, $depth = 1, $deep = false)
3333

3434
if (is_object($value)) {
3535
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
36-
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
36+
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ATOM));
3737
}
3838

3939
return sprintf('Object(%s)', get_class($value));

src/Symfony/Component/HttpKernel/Profiler/MemcacheProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function getMemcache()
4141
$port = $matches[3];
4242

4343
$memcache = new \Memcache();
44-
$memcache->addserver($host, $port);
44+
$memcache->addServer($host, $port);
4545

4646
$this->memcache = $memcache;
4747
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp()
2828
public function testDateTime()
2929
{
3030
$dateTime = new \DateTime('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
31-
$this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
31+
$this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+00:00', $this->valueExporter->exportValue($dateTime));
3232
}
3333

3434
/**
@@ -37,7 +37,7 @@ public function testDateTime()
3737
public function testDateTimeImmutable()
3838
{
3939
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
40-
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
40+
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+00:00', $this->valueExporter->exportValue($dateTime));
4141
}
4242

4343
public function testIncompleteClass()

src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,8 @@ protected function getSelectSecurityIdentityIdSql(SecurityIdentityInterface $sid
662662
protected function getDeleteSecurityIdentityIdSql(SecurityIdentityInterface $sid)
663663
{
664664
$select = $this->getSelectSecurityIdentityIdSql($sid);
665-
$delete = preg_replace('/^SELECT id FROM/', 'DELETE FROM', $select);
666665

667-
return $delete;
666+
return preg_replace('/^SELECT id FROM/', 'DELETE FROM', $select);
668667
}
669668

670669
/**

src/Symfony/Component/Translation/Tests/DataCollectorTranslatorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ private function createCollector()
6868
$translator->addResource('array', array('bar' => 'bar (fr)'), 'fr');
6969
$translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru');
7070

71-
$collector = new DataCollectorTranslator($translator);
72-
73-
return $collector;
71+
return new DataCollectorTranslator($translator);
7472
}
7573
}

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
610610
$previousLineIndented = false;
611611
$previousLineBlank = false;
612612

613-
for ($i = 0; $i < count($blockLines); ++$i) {
613+
for ($i = 0, $blockLinesCount = count($blockLines); $i < $blockLinesCount; ++$i) {
614614
if ('' === $blockLines[$i]) {
615615
$text .= "\n";
616616
$previousLineIndented = false;

0 commit comments

Comments
 (0)
0