Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[4.3] Remove unused local variables #34176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,11 @@ public function endTest($test, $time)
if (class_exists('PHPUnit_Util_Blacklist', false)) {
$Test = 'PHPUnit_Util_Test';
$BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner';
$Warning = 'PHPUnit_Framework_Warning';
} else {
$Test = 'PHPUnit\Util\Test';
$BaseTestRunner = 'PHPUnit\Runner\BaseTestRunner';
$Warning = 'PHPUnit\Framework\Warning';
}
$className = \get_class($test);
$classGroups = $Test::getGroups($className);
$groups = $Test::getGroups($className, $test->getName(false));

if (null !== $this->reportUselessTests) {
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Bridge/Twig/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public function compile(Compiler $compiler)
}
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);

$method = !$this->hasNode('count') ? 'trans' : 'transChoice';

$compiler
->write('echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
->subcompile($msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,6 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
{
$loader->load('assets.xml');

$defaultVersion = null;

if ($config['version_strategy']) {
$defaultVersion = new Reference($config['version_strategy']);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ public function load($resource, $type = null)
}
}

if (1 === substr_count($controller, ':')) {
$nonDeprecatedNotation = str_replace(':', '::', $controller);
// TODO deprecate this in 5.1
}

$route->setDefault('_controller', $controller);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class ContainerDumpTest extends AbstractWebTestCase
{
public function testContainerCompilationInDebug()
{
$client = $this->createClient(['test_case' => 'ContainerDump', 'root_config' => 'config.yml']);
$this->createClient(['test_case' => 'ContainerDump', 'root_config' => 'config.yml']);

$this->assertTrue(static::$container->has('serializer'));
}

public function testContainerCompilation()
{
$client = $this->createClient(['test_case' => 'ContainerDump', 'root_config' => 'config.yml', 'debug' => false]);
$this->createClient(['test_case' => 'ContainerDump', 'root_config' => 'config.yml', 'debug' => false]);

$this->assertTrue(static::$container->has('serializer'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public function providerCollectDecisionLog(): \Generator

$eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMockForAbstractClass();
$decoratedVoter1 = new TraceableVoter($voter1, $eventDispatcher);
$decoratedVoter2 = new TraceableVoter($voter2, $eventDispatcher);

yield [
AccessDecisionManager::STRATEGY_AFFIRMATIVE,
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function testRecursiveGet()
$cache = $this->createCachePool(0, __FUNCTION__);

$v = $cache->get('k1', function () use (&$counter, $cache) {
$v = $cache->get('k2', function () use (&$counter) { return ++$counter; });
$v = $cache->get('k2', function () use (&$counter) { return ++$counter; });
$cache->get('k2', function () use (&$counter) { return ++$counter; });
$v = $cache->get('k2', function () use (&$counter) { return ++$counter; }); // ensure the callback is called once

return $v;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testGet()
$adapter = $this->createCachePool();

$fetched = [];
$item = $adapter->get('myKey', function ($item) use (&$fetched) { $fetched[] = $item; });
$adapter->get('myKey', function ($item) use (&$fetched) { $fetched[] = $item; });
$this->assertCount(1, $fetched);
$item = $fetched[0];
$this->assertFalse($item->isHit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public static function setUpBeforeClass(): void
}

self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');

$pool = new PdoAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]));
}

public static function tearDownAfterClass(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ private function getMetaFile()

private function safelyUnserialize($file)
{
$e = null;
$meta = false;
$content = file_get_contents($file);
$signalingException = new \UnexpectedValueException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function testOverwriteMultipleLines()
public function testAddingMultipleSections()
{
$sections = [];
$output1 = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
$output2 = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());

$this->assertCount(2, $sections);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function getContent(bool $throw = true): string

if (null === $this->content) {
$content = null;
$chunk = null;

foreach (self::stream([$this]) as $chunk) {
if (!$chunk->isLast()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NativeFileSessionHandlerTest extends TestCase
{
public function testConstruct()
{
$storage = new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir()));
new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir()));

$this->assertEquals('user', ini_get('session.save_handler'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function testBindingsOnChildDefinitions()
public function testNotTaggedControllerServiceReceivesLocatorArgument()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.not_tagged_controller')->addArgument([]);
$container->register('argument_resolver.not_tagged_controller')->addArgument([]);

$pass = new RegisterControllerArgumentLocatorsPass();
$pass->process($container);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mailer/Tests/SmtpEnvelopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function testConstructorWithAddressRecipients()
public function testConstructorWithNoRecipients()
{
$this->expectException(\InvalidArgumentException::class);
$e = new SmtpEnvelope(new Address('[email protected]'), []);
new SmtpEnvelope(new Address('[email protected]'), []);
}

public function testConstructorWithWrongRecipients()
{
$this->expectException(\InvalidArgumentException::class);
$e = new SmtpEnvelope(new Address('[email protected]'), ['[email protected]']);
new SmtpEnvelope(new Address('[email protected]'), ['[email protected]']);
}

public function testSenderFromHeaders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function get(): ?array
$messageId = '0'; // will receive consumers pending messages
}

$e = null;
try {
$messages = $this->connection->xreadgroup(
$this->group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function encode(Envelope $envelope): array

private function safelyUnserialize($contents)
{
$e = null;
$signalingException = new MessageDecodingFailedException(sprintf('Could not decode message using PHP serialization: %s.', $contents));
$prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback');
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler, $signalingException) {
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Mime/CharacterStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public function read(int $length): ?string
if ($this->currentPos >= $this->charCount) {
return null;
}
$ret = null;
$length = ($this->currentPos + $length > $this->charCount) ? $this->charCount - $this->currentPos : $length;
if ($this->fixedWidth > 0) {
$len = $length * $this->fixedWidth;
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Mime/Tests/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ public function testGenerateBody()
$e->text('text content');
$e->attach($file);
$e->attach($image, 'test.gif');
$fullhtml = new TextPart($content, 'utf-8', 'html');
$inlinedimg = (new DataPart($image, 'test.gif'))->asInline();
$body = $e->getBody();
$this->assertInstanceOf(MixedPart::class, $body);
$this->assertCount(2, $related = $body->getParts());
Expand Down Expand Up @@ -378,7 +376,7 @@ public function testSerialize()
$e->from('[email protected]');
$e->text($r);
$e->html($r);
$contents = file_get_contents($name = __DIR__.'/Fixtures/mimetypes/test', 'r');
$name = __DIR__.'/Fixtures/mimetypes/test';
$file = fopen($name, 'r');
$e->attach($file, 'test');
$expected = clone $e;
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Component/Mime/Tests/Header/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ public function testAllReturnsEmptyArrayIfNoneSet()

public function testRemoveRemovesAllHeadersWithName()
{
$header0 = new UnstructuredHeader('X-Test', 'some@id');
$header1 = new UnstructuredHeader('X-Test', 'other@id');
$headers = new Headers();
$headers->addIdHeader('X-Test', 'some@id');
$headers->addIdHeader('X-Test', 'other@id');
Expand All @@ -185,7 +183,6 @@ public function testRemoveRemovesAllHeadersWithName()

public function testHasIsNotCaseSensitive()
{
$header = new IdentificationHeader('Message-ID', 'some@id');
$headers = new Headers();
$headers->addIdHeader('Message-ID', 'some@id');
$this->assertTrue($headers->has('message-id'));
Expand All @@ -209,7 +206,6 @@ public function testAllIsNotCaseSensitive()

public function testRemoveIsNotCaseSensitive()
{
$header = new IdentificationHeader('Message-ID', 'some@id');
$headers = new Headers();
$headers->addIdHeader('Message-ID', 'some@id');
$headers->remove('message-id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testInvalidIdLeftThrowsException()
{
$this->expectException('Exception');
$this->expectExceptionMessage('Email "a b c@d" does not comply with addr-spec of RFC 2822.');
$header = new IdentificationHeader('References', 'a b c@d');
new IdentificationHeader('References', 'a b c@d');
}

public function testIdRightCanBeDotAtom()
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testInvalidIdRightThrowsException()
{
$this->expectException('Exception');
$this->expectExceptionMessage('Email "a@b c d" does not comply with addr-spec of RFC 2822.');
$header = new IdentificationHeader('References', 'a@b c d');
new IdentificationHeader('References', 'a@b c d');
}

public function testMissingAtSignThrowsException()
Expand All @@ -149,7 +149,7 @@ public function testMissingAtSignThrowsException()
/* -- RFC 2822, 3.6.4.
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
*/
$header = new IdentificationHeader('References', 'abc');
new IdentificationHeader('References', 'abc');
}

public function testSetBody()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Tests/Header/PathHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testSingleAddressCanBeSetAndFetched()
public function testAddressMustComplyWithRfc2822()
{
$this->expectException('Exception');
$header = new PathHeader('Return-Path', new Address('chr [email protected]'));
new PathHeader('Return-Path', new Address('chr [email protected]'));
}

public function testValueIsAngleAddrWithValidAddress()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static function (\$condition, \$context, \$request) { // \$checkCondition
}
}
EOF;
$compiledRoutes[4] = $forDump ? $checkConditionCode .= ",\n" : eval('return '.$checkConditionCode.';');
$compiledRoutes[4] = $forDump ? $checkConditionCode.",\n" : eval('return '.$checkConditionCode.';');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this updated in the previous PR also and still merged - but FYI this is not exactly the same: using .= provides better memory usage (maybe the engine does the optimization already, I don't know).
But ok to change anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. I assumed a simple concat is faster than an assign + concat. It might worth it to take a look or to revert those changes. I don't want to cause a performance regression just by trying to "clean" the code.

} else {
$compiledRoutes[4] = $forDump ? " null, // \$checkCondition\n" : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testInvalidRouteParameter()
public function testTryingToSetLocalesDirectly()
{
$this->expectException('BadMethodCallException');
$route = new Route(['locales' => ['nl' => 'bar']]);
new Route(['locales' => ['nl' => 'bar']]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function testGenerateNonExistingRoute()
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());

$projectUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());
$url = $projectUrlGenerator->generate('NonExisting', []);
$projectUrlGenerator->generate('NonExisting', []);
}

public function testDumpForRouteWithDefaults()
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Security/Http/Tests/FirewallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Http\Firewall;
Expand Down Expand Up @@ -52,8 +51,6 @@ public function testOnKernelRequestRegistersExceptionListener()

public function testOnKernelRequestStopsWhenThereIsAResponse()
{
$response = new Response();

$called = [];

$first = function () use (&$called) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ protected function createChildContext(array $parentContext, $attribute/*, ?strin
{
if (\func_num_args() < 3) {
@trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED);
$format = null;
}
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Tests\Fixtures\CustomArrayObject;
use Symfony\Component\Validator\Tests\Fixtures\ToString;

class ConstraintViolationTest extends TestCase
{
Expand Down Expand Up @@ -114,7 +113,7 @@ public function testToStringOmitsEmptyCodes()
public function testMessageCannotBeArray()
{
$this->expectException(\TypeError::class);
$violation = new ConstraintViolation(
new ConstraintViolation(
['cannot be an array'],
'',
[],
Expand All @@ -127,7 +126,7 @@ public function testMessageCannotBeArray()
public function testMessageObjectMustBeStringable()
{
$this->expectException(\TypeError::class);
$violation = new ConstraintViolation(
new ConstraintViolation(
new CustomArrayObject(),
'',
[],
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function parse(string $value, int $flags = 0)
$this->refs = [];

$mbEncoding = null;
$data = null;

if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
$mbEncoding = mb_internal_encoding();
Expand Down