Skip to content

Commit 9eb2b14

Browse files
committed
Php Inspections (EA Extended):
- resolved possible PHP Fatal in \Symfony\Component\BrowserKit\Cookie::__toString -resolved implicit magic methods calls -resolved callable name case mismatches
1 parent a3ee1c5 commit 9eb2b14

File tree

21 files changed

+46
-43
lines changed

21 files changed

+46
-43
lines changed

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
6969
$this->rawValue = urlencode($value);
7070
}
7171
$this->name = $name;
72-
$this->expires = null === $expires ? null : (int) $expires;
7372
$this->path = empty($path) ? '/' : $path;
7473
$this->domain = $domain;
7574
$this->secure = (bool) $secure;
7675
$this->httponly = (bool) $httponly;
76+
77+
if (null !== $expires) {
78+
$timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
79+
if (false === $timestampAsDateTime) {
80+
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $expires);
81+
}
82+
83+
$this->expires = $timestampAsDateTime->getTimestamp();
84+
}
85+
7786
}
7887

7988
/**
@@ -91,12 +100,6 @@ public function __toString()
91100

92101
if (null !== $this->expires) {
93102
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
94-
95-
if ($dateTime === false) {
96-
// this throw will provoke PHP fatal
97-
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $this->expires);
98-
}
99-
100103
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::$dateFormats[0]));
101104
}
102105

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function testFollowRedirect()
332332
$client->followRedirect();
333333
$this->fail('->followRedirect() throws a \LogicException if the request was not redirected');
334334
} catch (\Exception $e) {
335-
$this->assertInstanceof('LogicException', $e, '->followRedirect() throws a \LogicException if the request was not redirected');
335+
$this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request was not redirected');
336336
}
337337

338338
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
@@ -362,7 +362,7 @@ public function testFollowRedirect()
362362
$client->followRedirect();
363363
$this->fail('->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code');
364364
} catch (\Exception $e) {
365-
$this->assertInstanceof('LogicException', $e, '->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code');
365+
$this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code');
366366
}
367367
}
368368

@@ -392,7 +392,7 @@ public function testFollowRedirectWithMaxRedirects()
392392
$client->followRedirect();
393393
$this->fail('->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
394394
} catch (\Exception $e) {
395-
$this->assertInstanceof('LogicException', $e, '->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
395+
$this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
396396
}
397397

398398
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
@@ -562,7 +562,7 @@ public function testInsulatedRequests()
562562
$client->request('GET', 'http://www.example.com/foo/foobar');
563563
$this->fail('->request() throws a \RuntimeException if the script has an error');
564564
} catch (\Exception $e) {
565-
$this->assertInstanceof('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error');
565+
$this->assertInstanceOf('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error');
566566
}
567567
}
568568

src/Symfony/Component/BrowserKit/Tests/CookieTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,30 @@ public function testFromStringWithCapitalization()
7474

7575
public function testFromStringWithUrl()
7676
{
77-
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com/'));
78-
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com'));
79-
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com?foo'));
80-
$this->assertEquals('foo=bar; domain=www.example.com; path=/foo', (string) Cookie::FromString('foo=bar', 'http://www.example.com/foo/bar'));
81-
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
82-
$this->assertEquals('foo=bar; domain=www.myotherexample.com; path=/', (string) Cookie::FromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));
77+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar', 'http://www.example.com/'));
78+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar', 'http://www.example.com'));
79+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar', 'http://www.example.com?foo'));
80+
$this->assertEquals('foo=bar; domain=www.example.com; path=/foo', (string) Cookie::fromString('foo=bar', 'http://www.example.com/foo/bar'));
81+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
82+
$this->assertEquals('foo=bar; domain=www.myotherexample.com; path=/', (string) Cookie::fromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));
8383
}
8484

8585
public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
8686
{
8787
$this->setExpectedException('InvalidArgumentException');
88-
Cookie::FromString('foo');
88+
Cookie::fromString('foo');
8989
}
9090

9191
public function testFromStringThrowsAnExceptionIfCookieDateIsNotValid()
9292
{
9393
$this->setExpectedException('InvalidArgumentException');
94-
Cookie::FromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');
94+
Cookie::fromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');
9595
}
9696

9797
public function testFromStringThrowsAnExceptionIfUrlIsNotValid()
9898
{
9999
$this->setExpectedException('InvalidArgumentException');
100-
Cookie::FromString('foo=bar', 'foobar');
100+
Cookie::fromString('foo=bar', 'foobar');
101101
}
102102

103103
public function testGetName()

src/Symfony/Component/BrowserKit/Tests/HistoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testCurrent()
5454
$history->current();
5555
$this->fail('->current() throws a \LogicException if the history is empty');
5656
} catch (\Exception $e) {
57-
$this->assertInstanceof('LogicException', $e, '->current() throws a \LogicException if the history is empty');
57+
$this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is empty');
5858
}
5959

6060
$history->add(new Request('http://www.example.com/', 'get'));
@@ -71,7 +71,7 @@ public function testBack()
7171
$history->back();
7272
$this->fail('->back() throws a \LogicException if the history is already on the first page');
7373
} catch (\Exception $e) {
74-
$this->assertInstanceof('LogicException', $e, '->current() throws a \LogicException if the history is already on the first page');
74+
$this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is already on the first page');
7575
}
7676

7777
$history->add(new Request('http://www.example1.com/', 'get'));
@@ -90,7 +90,7 @@ public function testForward()
9090
$history->forward();
9191
$this->fail('->forward() throws a \LogicException if the history is already on the last page');
9292
} catch (\Exception $e) {
93-
$this->assertInstanceof('LogicException', $e, '->forward() throws a \LogicException if the history is already on the last page');
93+
$this->assertInstanceOf('LogicException', $e, '->forward() throws a \LogicException if the history is already on the last page');
9494
}
9595

9696
$history->back();

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function testNotice()
107107
$that->assertEquals(E_NOTICE, $exception->getSeverity());
108108
$that->assertEquals(__LINE__ + 40, $exception->getLine());
109109
$that->assertEquals(__FILE__, $exception->getFile());
110-
$that->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
110+
$that->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
111111
$that->assertArrayHasKey('foobar', $exception->getContext());
112112

113113
$trace = $exception->getTrace();

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testDumpFrozenContainerWithNoParameter()
4949

5050
$dumpedString = $dumper->dump();
5151
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.');
52-
$this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
52+
$this->assertNotRegExp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
5353
}
5454

5555
public function testDumpOptimizationString()

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testSortByModifiedTime($adapter)
262262
public function testSort($adapter)
263263
{
264264
$finder = $this->buildFinder($adapter);
265-
$this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }));
265+
$this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
266266
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
267267
}
268268

src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getAcceptData()
163163
array(SortableIterator::SORT_BY_ACCESSED_TIME, $this->toAbsolute($sortByAccessedTime)),
164164
array(SortableIterator::SORT_BY_CHANGED_TIME, $this->toAbsolute($sortByChangedTime)),
165165
array(SortableIterator::SORT_BY_MODIFIED_TIME, $this->toAbsolute($sortByModifiedTime)),
166-
array(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }, $this->toAbsolute($customComparison)),
166+
array(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, $this->toAbsolute($customComparison)),
167167
);
168168
}
169169
}

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function reverseTransform($value)
219219
}
220220

221221
if ($this->inputTimezone !== $this->outputTimezone) {
222-
$dateTime->setTimeZone(new \DateTimeZone($this->inputTimezone));
222+
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
223223
}
224224
} catch (TransformationFailedException $e) {
225225
throw $e;

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function assertMatchesXpath($html, $expression, $count = 1)
6060
try {
6161
// Wrap in <root> node so we can load HTML with multiple tags at
6262
// the top level
63-
$dom->loadXml('<root>'.$html.'</root>');
63+
$dom->loadXML('<root>'.$html.'</root>');
6464
} catch (\Exception $e) {
6565
$this->fail(sprintf(
6666
"Failed loading HTML:\n\n%s\n\nError: %s",

0 commit comments

Comments
 (0)