diff --git a/rector.php b/rector.php index 14cd4a81e9..ec64a2c382 100644 --- a/rector.php +++ b/rector.php @@ -17,6 +17,7 @@ use Rector\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenc use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; use Rector\Core\Configuration\Option; use Rector\Core\ValueObject\PhpVersion; +use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector; use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector; use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector; @@ -99,4 +100,5 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->set(AddPregQuoteDelimiterRector::class); $services->set(SimplifyRegexPatternRector::class); $services->set(RemoveExtraParametersRector::class); + $services->set(RemoveUnusedVariableAssignRector::class); }; diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index 8701922e73..2988fe3e30 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -448,7 +448,7 @@ class ResponseTraitTest extends CIUnitTestCase $original = $_SERVER; $_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->response->setContentType($contentType); $this->assertEquals($contentType, $this->response->getHeaderLine('Content-Type'), 'Response header pre-response...'); diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index bb998f9302..d228c51b60 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -243,7 +243,6 @@ final class FileHandlerTest extends CIUnitTestCase public function testGetCacheInfo() { - $time = time(); $this->fileHandler->save(self::$key1, 'value'); $actual = $this->fileHandler->getCacheInfo(); diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index d67be6d671..4511d291c8 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -239,7 +239,7 @@ class CodeIgniterTest extends CIUnitTestCase ob_start(); $this->codeigniter->useSafeOutput(true)->run(); - $output = ob_get_clean(); + ob_get_clean(); $response = $this->getPrivateProperty($this->codeigniter, 'response'); @@ -284,7 +284,7 @@ class CodeIgniterTest extends CIUnitTestCase ob_start(); $codeigniter->useSafeOutput(true)->run(); - $output = ob_get_clean(); + ob_get_clean(); $this->assertEquals('https://example.com/', $response->header('Location')->getValue()); } diff --git a/tests/system/CommonFunctionsSendTest.php b/tests/system/CommonFunctionsSendTest.php index d87828de1f..5d09a71e8a 100644 --- a/tests/system/CommonFunctionsSendTest.php +++ b/tests/system/CommonFunctionsSendTest.php @@ -40,8 +40,6 @@ class CommonFunctionsSendTest extends CIUnitTestCase // send it ob_start(); $response->send(); - - $buffer = ob_clean(); if (ob_get_level() > 0) { ob_end_clean(); } diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 32e3ce357d..6a79871006 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -331,7 +331,7 @@ class CommonFunctionsTest extends CIUnitTestCase $_POST = ['location' => $locations]; $response = new RedirectResponse(new App()); - $returned = $response->withInput(); + $response->withInput(); $this->assertEquals($locations, old('location')); } @@ -383,8 +383,6 @@ class CommonFunctionsTest extends CIUnitTestCase { $loginTime = time(); - $response = new Response(new App()); - $routes = service('routes'); $routes->add('user/login', 'Auth::verify', ['as' => 'login']); diff --git a/tests/system/Database/Live/BadQueryTest.php b/tests/system/Database/Live/BadQueryTest.php index d32d949d98..d7af31b859 100644 --- a/tests/system/Database/Live/BadQueryTest.php +++ b/tests/system/Database/Live/BadQueryTest.php @@ -36,7 +36,7 @@ class BadQueryTest extends CIUnitTestCase $this->setPrivateProperty($this->db, 'DBDebug', true); // expect an exception, class and message varies by DBMS $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 } diff --git a/tests/system/Database/Live/DEBugTest.php b/tests/system/Database/Live/DEBugTest.php index dc387f2aa2..61bae0c566 100644 --- a/tests/system/Database/Live/DEBugTest.php +++ b/tests/system/Database/Live/DEBugTest.php @@ -18,7 +18,7 @@ class DEBugTest extends CIUnitTestCase { $this->setPrivateProperty($this->db, 'DBDebug', true); $this->expectException('Exception'); - $result = $this->db->simpleQuery('SELECT * FROM db_error'); + $this->db->simpleQuery('SELECT * FROM db_error'); } public function testDBDebugFalse() diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 1d2e8b004c..b07f374b23 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -573,7 +573,7 @@ class ForgeTest extends CIUnitTestCase $this->forge->addKey('id', true); $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'); $fieldsData = $this->db->getFieldData('forge_test_fields'); diff --git a/tests/system/Database/Live/SQLite/AlterTableTest.php b/tests/system/Database/Live/SQLite/AlterTableTest.php index 113b77aba7..a7286ccd07 100644 --- a/tests/system/Database/Live/SQLite/AlterTableTest.php +++ b/tests/system/Database/Live/SQLite/AlterTableTest.php @@ -208,7 +208,7 @@ class AlterTableTest extends CIUnitTestCase $this->seeInDatabase('foo', ['name' => 'George Clinton']); - $result = $this->table + $this->table ->fromTable('foo') ->dropColumn('name') ->run(); diff --git a/tests/system/Database/Live/UpdateTest.php b/tests/system/Database/Live/UpdateTest.php index 4de6968474..b0e51a2e4d 100644 --- a/tests/system/Database/Live/UpdateTest.php +++ b/tests/system/Database/Live/UpdateTest.php @@ -217,8 +217,6 @@ class UpdateTest extends CIUnitTestCase ->set('description', 'name', false) ->update(); - $result = $this->db->table('user')->get()->getResultArray(); - $this->seeInDatabase('job', [ 'name' => 'Developer', 'description' => 'Developer', diff --git a/tests/system/Files/FileTest.php b/tests/system/Files/FileTest.php index c954c5b102..dfccd4c016 100644 --- a/tests/system/Files/FileTest.php +++ b/tests/system/Files/FileTest.php @@ -75,6 +75,6 @@ class FileTest extends CIUnitTestCase { $this->expectException('CodeIgniter\Files\Exceptions\FileNotFoundException'); - $file = new File(SYSTEMPATH . 'Commoner.php', true); + new File(SYSTEMPATH . 'Commoner.php', true); } } diff --git a/tests/system/HTTP/ContentSecurityPolicyTest.php b/tests/system/HTTP/ContentSecurityPolicyTest.php index 818f9a9e57..cf08026acf 100644 --- a/tests/system/HTTP/ContentSecurityPolicyTest.php +++ b/tests/system/HTTP/ContentSecurityPolicyTest.php @@ -48,7 +48,7 @@ class ContentSecurityPolicyTest extends CIUnitTestCase public function testExistence() { $this->prepare(); - $result = $this->work(); + $this->work(); $this->assertHeaderEmitted('Content-Security-Policy:'); } @@ -63,7 +63,7 @@ class ContentSecurityPolicyTest extends CIUnitTestCase { $this->prepare(); $this->csp->reportOnly(false); - $result = $this->work(); + $this->work(); $this->assertHeaderEmitted('Content-Security-Policy:'); } @@ -515,7 +515,7 @@ class ContentSecurityPolicyTest extends CIUnitTestCase public function testCSPDisabled() { $this->prepare(false); - $result = $this->work(); + $this->work(); $this->response->CSP->addStyleSrc('https://example.com'); $this->assertHeaderNotEmitted('content-security-policy', true); diff --git a/tests/system/HTTP/DownloadResponseTest.php b/tests/system/HTTP/DownloadResponseTest.php index 96cc8841fd..eb0f5ddde0 100644 --- a/tests/system/HTTP/DownloadResponseTest.php +++ b/tests/system/HTTP/DownloadResponseTest.php @@ -300,8 +300,6 @@ class DownloadResponseTest extends CIUnitTestCase // send it ob_start(); $response->send(); - - $buffer = ob_clean(); if (ob_get_level() > 0) { ob_end_clean(); } diff --git a/tests/system/HTTP/ResponseSendTest.php b/tests/system/HTTP/ResponseSendTest.php index 261fffeb52..e776b3805a 100644 --- a/tests/system/HTTP/ResponseSendTest.php +++ b/tests/system/HTTP/ResponseSendTest.php @@ -50,8 +50,6 @@ class ResponseSendTest extends CIUnitTestCase // send it ob_start(); $response->send(); - - $buffer = ob_clean(); if (ob_get_level() > 0) { ob_end_clean(); } @@ -86,8 +84,6 @@ class ResponseSendTest extends CIUnitTestCase // send it ob_start(); $response->send(); - - $buffer = ob_clean(); if (ob_get_level() > 0) { ob_end_clean(); } @@ -125,8 +121,6 @@ class ResponseSendTest extends CIUnitTestCase // send it ob_start(); $response->send(); - - $buffer = ob_clean(); if (ob_get_level() > 0) { ob_end_clean(); } diff --git a/tests/system/HTTP/ResponseTest.php b/tests/system/HTTP/ResponseTest.php index d0ad3d4023..81ef36a3ef 100644 --- a/tests/system/HTTP/ResponseTest.php +++ b/tests/system/HTTP/ResponseTest.php @@ -245,8 +245,6 @@ class ResponseTest extends CIUnitTestCase { $response = new Response(new App()); - $date = date('r'); - $options = []; $response->setCache($options); diff --git a/tests/system/HTTP/URITest.php b/tests/system/HTTP/URITest.php index 20390c829b..a392c25e59 100644 --- a/tests/system/HTTP/URITest.php +++ b/tests/system/HTTP/URITest.php @@ -468,8 +468,6 @@ class URITest extends CIUnitTestCase $url = 'http://example.com/path'; $uri = new URI($url); - $expected = 'http://example.com/path?key=value'; - $this->expectException(HTTPException::class); $uri->setQuery('?key=value#fragment'); } diff --git a/tests/system/Helpers/DateHelperTest.php b/tests/system/Helpers/DateHelperTest.php index 262a2a37bf..44d5e1d859 100644 --- a/tests/system/Helpers/DateHelperTest.php +++ b/tests/system/Helpers/DateHelperTest.php @@ -17,7 +17,6 @@ final class DateHelperTest extends CIUnitTestCase public function testNowDefault() { - $time = new DateTime(); $this->assertCloseEnough(now(), time()); // close enough } diff --git a/tests/system/Helpers/FilesystemHelperTest.php b/tests/system/Helpers/FilesystemHelperTest.php index 9b6a6eba6f..5b409c0eee 100644 --- a/tests/system/Helpers/FilesystemHelperTest.php +++ b/tests/system/Helpers/FilesystemHelperTest.php @@ -113,7 +113,7 @@ class FilesystemHelperTest extends CIUnitTestCase // Create a subdirectory $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; directory_mirror($root . 'foo', $root . 'boo'); @@ -130,7 +130,7 @@ class FilesystemHelperTest extends CIUnitTestCase $this->structure['foo']['far'] = 'all your base'; $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; 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']['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; directory_mirror($root . 'foo', $root . 'boo', false); @@ -168,7 +168,7 @@ class FilesystemHelperTest extends CIUnitTestCase public function testWriteFileFailure() { - $vfs = vfsStream::setup('root'); + vfsStream::setup('root'); $this->assertFalse(write_file(vfsStream::url('apple#test.php'), 'Simple')); } diff --git a/tests/system/Helpers/URLHelper/MiscUrlTest.php b/tests/system/Helpers/URLHelper/MiscUrlTest.php index 2752932482..02436c2a90 100644 --- a/tests/system/Helpers/URLHelper/MiscUrlTest.php +++ b/tests/system/Helpers/URLHelper/MiscUrlTest.php @@ -72,7 +72,6 @@ final class MiscUrlTest extends CIUnitTestCase public function testPreviousURLUsesRefererIfNeeded() { $uri1 = 'http://example.com/one?two'; - $uri2 = 'http://example.com/two?foo'; $_SERVER['HTTP_REFERER'] = $uri1; diff --git a/tests/system/Images/BaseHandlerTest.php b/tests/system/Images/BaseHandlerTest.php index ced0f212e6..6a3f42cd76 100644 --- a/tests/system/Images/BaseHandlerTest.php +++ b/tests/system/Images/BaseHandlerTest.php @@ -39,7 +39,7 @@ class BaseHandlerTest extends CIUnitTestCase ]; vfsStream::create($structure); // with one of them read only - $wont = $this->root->getChild('wontwork')->chmod(0400); + $this->root->getChild('wontwork')->chmod(0400); // for VFS tests $this->start = $this->root->url() . '/'; diff --git a/tests/system/Images/GDHandlerTest.php b/tests/system/Images/GDHandlerTest.php index a04a4126cb..3a9cc6b4ef 100644 --- a/tests/system/Images/GDHandlerTest.php +++ b/tests/system/Images/GDHandlerTest.php @@ -37,7 +37,7 @@ class GDHandlerTest extends CIUnitTestCase ]; vfsStream::create($structure); // with one of them read only - $wont = $this->root->getChild('wontwork')->chmod(0400); + $this->root->getChild('wontwork')->chmod(0400); $this->start = $this->root->url() . '/'; diff --git a/tests/system/Images/ImageTest.php b/tests/system/Images/ImageTest.php index 44d150e256..e4ac95960c 100644 --- a/tests/system/Images/ImageTest.php +++ b/tests/system/Images/ImageTest.php @@ -24,7 +24,7 @@ class ImageTest extends CIUnitTestCase ]; vfsStream::create($structure); // with one of them read only - $wont = $this->root->getChild('wontwork')->chmod(0400); + $this->root->getChild('wontwork')->chmod(0400); $this->start = $this->root->url() . '/'; diff --git a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php index 032cf94de2..297808d0ab 100644 --- a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php +++ b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php @@ -72,7 +72,7 @@ class ChromeLoggerHandlerTest extends CIUnitTestCase $data = new stdClass(); $data->code = 123; $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); diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index d869faf133..bd8deeea9f 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -874,7 +874,7 @@ class RouteCollectionTest extends CIUnitTestCase $routes->add('path/(:any)/to/(:num)', 'myController::goto/$1/$2'); $this->expectException(RouterException::class); - $match = $routes->reverseRoute('myController::goto', 13, 'string'); + $routes->reverseRoute('myController::goto', 13, 'string'); } //-------------------------------------------------------------------- diff --git a/tests/system/Test/ControllerTestTraitTest.php b/tests/system/Test/ControllerTestTraitTest.php index e93089fba2..5933140925 100644 --- a/tests/system/Test/ControllerTestTraitTest.php +++ b/tests/system/Test/ControllerTestTraitTest.php @@ -25,7 +25,7 @@ class ControllerTestTraitTest extends CIUnitTestCase { $this->expectException(InvalidArgumentException::class); $logger = new Logger(new LoggerConfig()); - $result = $this->withURI('http://example.com') + $this->withURI('http://example.com') ->withLogger($logger) ->controller(NeverHeardOfIt::class) ->execute('index'); @@ -35,7 +35,7 @@ class ControllerTestTraitTest extends CIUnitTestCase { $this->expectException(InvalidArgumentException::class); $logger = new Logger(new LoggerConfig()); - $result = $this->withURI('http://example.com') + $this->withURI('http://example.com') ->withLogger($logger) ->controller(Home::class) ->execute('nothere'); @@ -49,7 +49,6 @@ class ControllerTestTraitTest extends CIUnitTestCase ->controller(Home::class) ->execute('index'); - $body = $result->response()->getBody(); $this->assertTrue($result->isOK()); } @@ -59,7 +58,6 @@ class ControllerTestTraitTest extends CIUnitTestCase ->controller(Home::class) ->execute('index'); - $body = $result->response()->getBody(); $this->assertTrue($result->isOK()); } @@ -71,7 +69,6 @@ class ControllerTestTraitTest extends CIUnitTestCase ->controller(Popcorn::class) ->execute('index'); - $body = $result->response()->getBody(); $this->assertTrue($result->isOK()); } @@ -222,7 +219,6 @@ class ControllerTestTraitTest extends CIUnitTestCase ->controller(Home::class) ->execute('index'); - $body = $result->response()->getBody(); $this->assertTrue($result->isOK()); } diff --git a/tests/system/Test/FabricatorTest.php b/tests/system/Test/FabricatorTest.php index 9db734c9d5..4ff7955f04 100644 --- a/tests/system/Test/FabricatorTest.php +++ b/tests/system/Test/FabricatorTest.php @@ -55,7 +55,7 @@ class FabricatorTest extends CIUnitTestCase $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(lang('Fabricator.invalidModel')); - $fabricator = new Fabricator('SillyRabbit\Models\AreForKids'); + new Fabricator('SillyRabbit\Models\AreForKids'); } public function testConstructorSetsFormatters() diff --git a/tests/system/Test/FilterTestTraitTest.php b/tests/system/Test/FilterTestTraitTest.php index 773a0b0836..9df20bdd79 100644 --- a/tests/system/Test/FilterTestTraitTest.php +++ b/tests/system/Test/FilterTestTraitTest.php @@ -54,7 +54,7 @@ class FilterTestTraitTest extends CIUnitTestCase $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Invalid filter position passed: banana'); - $caller = $this->getFilterCaller('test-customfilter', 'banana'); + $this->getFilterCaller('test-customfilter', 'banana'); } public function testCallerUsesClonedInstance() diff --git a/tests/system/Test/TestCaseEmissionsTest.php b/tests/system/Test/TestCaseEmissionsTest.php index 9e2e45b92a..4bacbb2b9f 100644 --- a/tests/system/Test/TestCaseEmissionsTest.php +++ b/tests/system/Test/TestCaseEmissionsTest.php @@ -49,8 +49,6 @@ class TestCaseEmissionsTest extends CIUnitTestCase // send it ob_start(); $response->send(); - - $buffer = ob_clean(); if (ob_get_level() > 0) { ob_end_clean(); } @@ -81,8 +79,7 @@ class TestCaseEmissionsTest extends CIUnitTestCase // send it ob_start(); - $response->send(); - $output = ob_clean(); // what really was sent + $response->send(); // what really was sent if (ob_get_level() > 0) { ob_end_clean(); } diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index 8883e55a4d..40f2a3d924 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -451,10 +451,6 @@ final class ValidationTest extends CIUnitTestCase $config->baseURL = 'http://example.com/'; $request = new IncomingRequest($config, new URI(), $rawstring, new UserAgent()); - - $rules = [ - 'role' => 'required|min_length[5]', - ]; $this->validation->withRequest($request->withMethod('patch'))->run($data); $this->assertEquals([], $this->validation->getErrors()); } diff --git a/tests/system/View/ParserFilterTest.php b/tests/system/View/ParserFilterTest.php index d2b9f001c4..050fe7d5b8 100644 --- a/tests/system/View/ParserFilterTest.php +++ b/tests/system/View/ParserFilterTest.php @@ -85,8 +85,6 @@ class ParserFilterTest extends CIUnitTestCase public function testDateModify() { $parser = new Parser($this->config, $this->viewsDir, $this->loader); - - $today = date('Y-m-d'); $tommorrow = date('Y-m-d', strtotime('+1 day')); $data = [ diff --git a/tests/system/View/ViewTest.php b/tests/system/View/ViewTest.php index 1e65901efd..351deb6224 100644 --- a/tests/system/View/ViewTest.php +++ b/tests/system/View/ViewTest.php @@ -328,7 +328,6 @@ class ViewTest extends CIUnitTestCase $view = new View($this->config, $this->viewsDir, $this->loader); $view->setVar('testString', 'Hello World'); - $expected = "
Open
\n