[Rector] Apply Rector: RemoveUnusedVariableAssignRector

This commit is contained in:
Abdul Malik Ikhsan 2021-06-24 15:43:23 +07:00
parent e73f750f22
commit 398b329cd7
No known key found for this signature in database
GPG Key ID: 69AC5BC354C89BE6
32 changed files with 28 additions and 61 deletions

View File

@ -17,6 +17,7 @@ use Rector\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenc
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion; use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector; use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector; use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector; use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
@ -99,4 +100,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddPregQuoteDelimiterRector::class); $services->set(AddPregQuoteDelimiterRector::class);
$services->set(SimplifyRegexPatternRector::class); $services->set(SimplifyRegexPatternRector::class);
$services->set(RemoveExtraParametersRector::class); $services->set(RemoveExtraParametersRector::class);
$services->set(RemoveUnusedVariableAssignRector::class);
}; };

View File

@ -448,7 +448,7 @@ class ResponseTraitTest extends CIUnitTestCase
$original = $_SERVER; $original = $_SERVER;
$_SERVER['CONTENT_TYPE'] = $mimeType; $_SERVER['CONTENT_TYPE'] = $mimeType;
$controller = $this->makeController([], 'http://codeigniter.com', ['Accept' => $mimeType]); $this->makeController([], 'http://codeigniter.com', ['Accept' => $mimeType]);
$this->assertEquals($mimeType, $this->request->getHeaderLine('Accept'), 'Request header...'); $this->assertEquals($mimeType, $this->request->getHeaderLine('Accept'), 'Request header...');
$this->response->setContentType($contentType); $this->response->setContentType($contentType);
$this->assertEquals($contentType, $this->response->getHeaderLine('Content-Type'), 'Response header pre-response...'); $this->assertEquals($contentType, $this->response->getHeaderLine('Content-Type'), 'Response header pre-response...');

View File

@ -243,7 +243,6 @@ final class FileHandlerTest extends CIUnitTestCase
public function testGetCacheInfo() public function testGetCacheInfo()
{ {
$time = time();
$this->fileHandler->save(self::$key1, 'value'); $this->fileHandler->save(self::$key1, 'value');
$actual = $this->fileHandler->getCacheInfo(); $actual = $this->fileHandler->getCacheInfo();

View File

@ -239,7 +239,7 @@ class CodeIgniterTest extends CIUnitTestCase
ob_start(); ob_start();
$this->codeigniter->useSafeOutput(true)->run(); $this->codeigniter->useSafeOutput(true)->run();
$output = ob_get_clean(); ob_get_clean();
$response = $this->getPrivateProperty($this->codeigniter, 'response'); $response = $this->getPrivateProperty($this->codeigniter, 'response');
@ -284,7 +284,7 @@ class CodeIgniterTest extends CIUnitTestCase
ob_start(); ob_start();
$codeigniter->useSafeOutput(true)->run(); $codeigniter->useSafeOutput(true)->run();
$output = ob_get_clean(); ob_get_clean();
$this->assertEquals('https://example.com/', $response->header('Location')->getValue()); $this->assertEquals('https://example.com/', $response->header('Location')->getValue());
} }

View File

@ -40,8 +40,6 @@ class CommonFunctionsSendTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send();
$buffer = ob_clean();
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }

View File

@ -331,7 +331,7 @@ class CommonFunctionsTest extends CIUnitTestCase
$_POST = ['location' => $locations]; $_POST = ['location' => $locations];
$response = new RedirectResponse(new App()); $response = new RedirectResponse(new App());
$returned = $response->withInput(); $response->withInput();
$this->assertEquals($locations, old('location')); $this->assertEquals($locations, old('location'));
} }
@ -383,8 +383,6 @@ class CommonFunctionsTest extends CIUnitTestCase
{ {
$loginTime = time(); $loginTime = time();
$response = new Response(new App());
$routes = service('routes'); $routes = service('routes');
$routes->add('user/login', 'Auth::verify', ['as' => 'login']); $routes->add('user/login', 'Auth::verify', ['as' => 'login']);

View File

@ -36,7 +36,7 @@ class BadQueryTest extends CIUnitTestCase
$this->setPrivateProperty($this->db, 'DBDebug', true); $this->setPrivateProperty($this->db, 'DBDebug', true);
// expect an exception, class and message varies by DBMS // expect an exception, class and message varies by DBMS
$this->expectException(Exception::class); $this->expectException(Exception::class);
$query = $this->db->query('SELECT * FROM table_does_not_exist'); $this->db->query('SELECT * FROM table_does_not_exist');
// this code is never executed // this code is never executed
} }

View File

@ -18,7 +18,7 @@ class DEBugTest extends CIUnitTestCase
{ {
$this->setPrivateProperty($this->db, 'DBDebug', true); $this->setPrivateProperty($this->db, 'DBDebug', true);
$this->expectException('Exception'); $this->expectException('Exception');
$result = $this->db->simpleQuery('SELECT * FROM db_error'); $this->db->simpleQuery('SELECT * FROM db_error');
} }
public function testDBDebugFalse() public function testDBDebugFalse()

View File

@ -573,7 +573,7 @@ class ForgeTest extends CIUnitTestCase
$this->forge->addKey('id', true); $this->forge->addKey('id', true);
$this->forge->addUniqueKey(['username', 'active']); $this->forge->addUniqueKey(['username', 'active']);
$create = $this->forge->createTable('forge_test_fields', true); $this->forge->createTable('forge_test_fields', true);
$fieldsNames = $this->db->getFieldNames('forge_test_fields'); $fieldsNames = $this->db->getFieldNames('forge_test_fields');
$fieldsData = $this->db->getFieldData('forge_test_fields'); $fieldsData = $this->db->getFieldData('forge_test_fields');

View File

@ -208,7 +208,7 @@ class AlterTableTest extends CIUnitTestCase
$this->seeInDatabase('foo', ['name' => 'George Clinton']); $this->seeInDatabase('foo', ['name' => 'George Clinton']);
$result = $this->table $this->table
->fromTable('foo') ->fromTable('foo')
->dropColumn('name') ->dropColumn('name')
->run(); ->run();

View File

@ -217,8 +217,6 @@ class UpdateTest extends CIUnitTestCase
->set('description', 'name', false) ->set('description', 'name', false)
->update(); ->update();
$result = $this->db->table('user')->get()->getResultArray();
$this->seeInDatabase('job', [ $this->seeInDatabase('job', [
'name' => 'Developer', 'name' => 'Developer',
'description' => 'Developer', 'description' => 'Developer',

View File

@ -75,6 +75,6 @@ class FileTest extends CIUnitTestCase
{ {
$this->expectException('CodeIgniter\Files\Exceptions\FileNotFoundException'); $this->expectException('CodeIgniter\Files\Exceptions\FileNotFoundException');
$file = new File(SYSTEMPATH . 'Commoner.php', true); new File(SYSTEMPATH . 'Commoner.php', true);
} }
} }

View File

@ -48,7 +48,7 @@ class ContentSecurityPolicyTest extends CIUnitTestCase
public function testExistence() public function testExistence()
{ {
$this->prepare(); $this->prepare();
$result = $this->work(); $this->work();
$this->assertHeaderEmitted('Content-Security-Policy:'); $this->assertHeaderEmitted('Content-Security-Policy:');
} }
@ -63,7 +63,7 @@ class ContentSecurityPolicyTest extends CIUnitTestCase
{ {
$this->prepare(); $this->prepare();
$this->csp->reportOnly(false); $this->csp->reportOnly(false);
$result = $this->work(); $this->work();
$this->assertHeaderEmitted('Content-Security-Policy:'); $this->assertHeaderEmitted('Content-Security-Policy:');
} }
@ -515,7 +515,7 @@ class ContentSecurityPolicyTest extends CIUnitTestCase
public function testCSPDisabled() public function testCSPDisabled()
{ {
$this->prepare(false); $this->prepare(false);
$result = $this->work(); $this->work();
$this->response->CSP->addStyleSrc('https://example.com'); $this->response->CSP->addStyleSrc('https://example.com');
$this->assertHeaderNotEmitted('content-security-policy', true); $this->assertHeaderNotEmitted('content-security-policy', true);

View File

@ -300,8 +300,6 @@ class DownloadResponseTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send();
$buffer = ob_clean();
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }

View File

@ -50,8 +50,6 @@ class ResponseSendTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send();
$buffer = ob_clean();
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }
@ -86,8 +84,6 @@ class ResponseSendTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send();
$buffer = ob_clean();
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }
@ -125,8 +121,6 @@ class ResponseSendTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send();
$buffer = ob_clean();
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }

View File

@ -245,8 +245,6 @@ class ResponseTest extends CIUnitTestCase
{ {
$response = new Response(new App()); $response = new Response(new App());
$date = date('r');
$options = []; $options = [];
$response->setCache($options); $response->setCache($options);

View File

@ -468,8 +468,6 @@ class URITest extends CIUnitTestCase
$url = 'http://example.com/path'; $url = 'http://example.com/path';
$uri = new URI($url); $uri = new URI($url);
$expected = 'http://example.com/path?key=value';
$this->expectException(HTTPException::class); $this->expectException(HTTPException::class);
$uri->setQuery('?key=value#fragment'); $uri->setQuery('?key=value#fragment');
} }

View File

@ -17,7 +17,6 @@ final class DateHelperTest extends CIUnitTestCase
public function testNowDefault() public function testNowDefault()
{ {
$time = new DateTime();
$this->assertCloseEnough(now(), time()); // close enough $this->assertCloseEnough(now(), time()); // close enough
} }

View File

@ -113,7 +113,7 @@ class FilesystemHelperTest extends CIUnitTestCase
// Create a subdirectory // Create a subdirectory
$this->structure['foo']['bam'] = ['zab' => 'A deep file']; $this->structure['foo']['bam'] = ['zab' => 'A deep file'];
$vfs = vfsStream::setup('root', null, $this->structure); vfsStream::setup('root', null, $this->structure);
$root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
directory_mirror($root . 'foo', $root . 'boo'); directory_mirror($root . 'foo', $root . 'boo');
@ -130,7 +130,7 @@ class FilesystemHelperTest extends CIUnitTestCase
$this->structure['foo']['far'] = 'all your base'; $this->structure['foo']['far'] = 'all your base';
$this->structure['foo']['faz'] = 'are belong to us'; $this->structure['foo']['faz'] = 'are belong to us';
$vfs = vfsStream::setup('root', null, $this->structure); vfsStream::setup('root', null, $this->structure);
$root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
directory_mirror($root . 'foo', $root . 'boo', true); directory_mirror($root . 'foo', $root . 'boo', true);
@ -147,7 +147,7 @@ class FilesystemHelperTest extends CIUnitTestCase
$this->structure['foo']['far'] = 'all your base'; $this->structure['foo']['far'] = 'all your base';
$this->structure['foo']['faz'] = 'are belong to us'; $this->structure['foo']['faz'] = 'are belong to us';
$vfs = vfsStream::setup('root', null, $this->structure); vfsStream::setup('root', null, $this->structure);
$root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
directory_mirror($root . 'foo', $root . 'boo', false); directory_mirror($root . 'foo', $root . 'boo', false);
@ -168,7 +168,7 @@ class FilesystemHelperTest extends CIUnitTestCase
public function testWriteFileFailure() public function testWriteFileFailure()
{ {
$vfs = vfsStream::setup('root'); vfsStream::setup('root');
$this->assertFalse(write_file(vfsStream::url('apple#test.php'), 'Simple')); $this->assertFalse(write_file(vfsStream::url('apple#test.php'), 'Simple'));
} }

View File

@ -72,7 +72,6 @@ final class MiscUrlTest extends CIUnitTestCase
public function testPreviousURLUsesRefererIfNeeded() public function testPreviousURLUsesRefererIfNeeded()
{ {
$uri1 = 'http://example.com/one?two'; $uri1 = 'http://example.com/one?two';
$uri2 = 'http://example.com/two?foo';
$_SERVER['HTTP_REFERER'] = $uri1; $_SERVER['HTTP_REFERER'] = $uri1;

View File

@ -39,7 +39,7 @@ class BaseHandlerTest extends CIUnitTestCase
]; ];
vfsStream::create($structure); vfsStream::create($structure);
// with one of them read only // with one of them read only
$wont = $this->root->getChild('wontwork')->chmod(0400); $this->root->getChild('wontwork')->chmod(0400);
// for VFS tests // for VFS tests
$this->start = $this->root->url() . '/'; $this->start = $this->root->url() . '/';

View File

@ -37,7 +37,7 @@ class GDHandlerTest extends CIUnitTestCase
]; ];
vfsStream::create($structure); vfsStream::create($structure);
// with one of them read only // with one of them read only
$wont = $this->root->getChild('wontwork')->chmod(0400); $this->root->getChild('wontwork')->chmod(0400);
$this->start = $this->root->url() . '/'; $this->start = $this->root->url() . '/';

View File

@ -24,7 +24,7 @@ class ImageTest extends CIUnitTestCase
]; ];
vfsStream::create($structure); vfsStream::create($structure);
// with one of them read only // with one of them read only
$wont = $this->root->getChild('wontwork')->chmod(0400); $this->root->getChild('wontwork')->chmod(0400);
$this->start = $this->root->url() . '/'; $this->start = $this->root->url() . '/';

View File

@ -72,7 +72,7 @@ class ChromeLoggerHandlerTest extends CIUnitTestCase
$data = new stdClass(); $data = new stdClass();
$data->code = 123; $data->code = 123;
$data->explanation = "That's no moon, it's a pumpkin"; $data->explanation = "That's no moon, it's a pumpkin";
$result = $logger->setDateFormat('F j, Y'); $logger->setDateFormat('F j, Y');
$logger->handle('warning', $data); $logger->handle('warning', $data);

View File

@ -874,7 +874,7 @@ class RouteCollectionTest extends CIUnitTestCase
$routes->add('path/(:any)/to/(:num)', 'myController::goto/$1/$2'); $routes->add('path/(:any)/to/(:num)', 'myController::goto/$1/$2');
$this->expectException(RouterException::class); $this->expectException(RouterException::class);
$match = $routes->reverseRoute('myController::goto', 13, 'string'); $routes->reverseRoute('myController::goto', 13, 'string');
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------

View File

@ -25,7 +25,7 @@ class ControllerTestTraitTest extends CIUnitTestCase
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$logger = new Logger(new LoggerConfig()); $logger = new Logger(new LoggerConfig());
$result = $this->withURI('http://example.com') $this->withURI('http://example.com')
->withLogger($logger) ->withLogger($logger)
->controller(NeverHeardOfIt::class) ->controller(NeverHeardOfIt::class)
->execute('index'); ->execute('index');
@ -35,7 +35,7 @@ class ControllerTestTraitTest extends CIUnitTestCase
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$logger = new Logger(new LoggerConfig()); $logger = new Logger(new LoggerConfig());
$result = $this->withURI('http://example.com') $this->withURI('http://example.com')
->withLogger($logger) ->withLogger($logger)
->controller(Home::class) ->controller(Home::class)
->execute('nothere'); ->execute('nothere');
@ -49,7 +49,6 @@ class ControllerTestTraitTest extends CIUnitTestCase
->controller(Home::class) ->controller(Home::class)
->execute('index'); ->execute('index');
$body = $result->response()->getBody();
$this->assertTrue($result->isOK()); $this->assertTrue($result->isOK());
} }
@ -59,7 +58,6 @@ class ControllerTestTraitTest extends CIUnitTestCase
->controller(Home::class) ->controller(Home::class)
->execute('index'); ->execute('index');
$body = $result->response()->getBody();
$this->assertTrue($result->isOK()); $this->assertTrue($result->isOK());
} }
@ -71,7 +69,6 @@ class ControllerTestTraitTest extends CIUnitTestCase
->controller(Popcorn::class) ->controller(Popcorn::class)
->execute('index'); ->execute('index');
$body = $result->response()->getBody();
$this->assertTrue($result->isOK()); $this->assertTrue($result->isOK());
} }
@ -222,7 +219,6 @@ class ControllerTestTraitTest extends CIUnitTestCase
->controller(Home::class) ->controller(Home::class)
->execute('index'); ->execute('index');
$body = $result->response()->getBody();
$this->assertTrue($result->isOK()); $this->assertTrue($result->isOK());
} }

View File

@ -55,7 +55,7 @@ class FabricatorTest extends CIUnitTestCase
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(lang('Fabricator.invalidModel')); $this->expectExceptionMessage(lang('Fabricator.invalidModel'));
$fabricator = new Fabricator('SillyRabbit\Models\AreForKids'); new Fabricator('SillyRabbit\Models\AreForKids');
} }
public function testConstructorSetsFormatters() public function testConstructorSetsFormatters()

View File

@ -54,7 +54,7 @@ class FilterTestTraitTest extends CIUnitTestCase
$this->expectException('InvalidArgumentException'); $this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid filter position passed: banana'); $this->expectExceptionMessage('Invalid filter position passed: banana');
$caller = $this->getFilterCaller('test-customfilter', 'banana'); $this->getFilterCaller('test-customfilter', 'banana');
} }
public function testCallerUsesClonedInstance() public function testCallerUsesClonedInstance()

View File

@ -49,8 +49,6 @@ class TestCaseEmissionsTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send();
$buffer = ob_clean();
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }
@ -81,8 +79,7 @@ class TestCaseEmissionsTest extends CIUnitTestCase
// send it // send it
ob_start(); ob_start();
$response->send(); $response->send(); // what really was sent
$output = ob_clean(); // what really was sent
if (ob_get_level() > 0) { if (ob_get_level() > 0) {
ob_end_clean(); ob_end_clean();
} }

View File

@ -451,10 +451,6 @@ final class ValidationTest extends CIUnitTestCase
$config->baseURL = 'http://example.com/'; $config->baseURL = 'http://example.com/';
$request = new IncomingRequest($config, new URI(), $rawstring, new UserAgent()); $request = new IncomingRequest($config, new URI(), $rawstring, new UserAgent());
$rules = [
'role' => 'required|min_length[5]',
];
$this->validation->withRequest($request->withMethod('patch'))->run($data); $this->validation->withRequest($request->withMethod('patch'))->run($data);
$this->assertEquals([], $this->validation->getErrors()); $this->assertEquals([], $this->validation->getErrors());
} }

View File

@ -85,8 +85,6 @@ class ParserFilterTest extends CIUnitTestCase
public function testDateModify() public function testDateModify()
{ {
$parser = new Parser($this->config, $this->viewsDir, $this->loader); $parser = new Parser($this->config, $this->viewsDir, $this->loader);
$today = date('Y-m-d');
$tommorrow = date('Y-m-d', strtotime('+1 day')); $tommorrow = date('Y-m-d', strtotime('+1 day'));
$data = [ $data = [

View File

@ -328,7 +328,6 @@ class ViewTest extends CIUnitTestCase
$view = new View($this->config, $this->viewsDir, $this->loader); $view = new View($this->config, $this->viewsDir, $this->loader);
$view->setVar('testString', 'Hello World'); $view->setVar('testString', 'Hello World');
$expected = "<p>Open</p>\n<h1>Hello World</h1>";
$content = $view->render('extend_include'); $content = $view->render('extend_include');