mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
[Rector] Apply Rector: RemoveUnusedVariableAssignRector
This commit is contained in:
parent
e73f750f22
commit
398b329cd7
@ -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);
|
||||
};
|
||||
|
@ -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...');
|
||||
|
@ -243,7 +243,6 @@ final class FileHandlerTest extends CIUnitTestCase
|
||||
|
||||
public function testGetCacheInfo()
|
||||
{
|
||||
$time = time();
|
||||
$this->fileHandler->save(self::$key1, 'value');
|
||||
|
||||
$actual = $this->fileHandler->getCacheInfo();
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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']);
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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');
|
||||
|
@ -208,7 +208,7 @@ class AlterTableTest extends CIUnitTestCase
|
||||
|
||||
$this->seeInDatabase('foo', ['name' => 'George Clinton']);
|
||||
|
||||
$result = $this->table
|
||||
$this->table
|
||||
->fromTable('foo')
|
||||
->dropColumn('name')
|
||||
->run();
|
||||
|
@ -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',
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -245,8 +245,6 @@ class ResponseTest extends CIUnitTestCase
|
||||
{
|
||||
$response = new Response(new App());
|
||||
|
||||
$date = date('r');
|
||||
|
||||
$options = [];
|
||||
|
||||
$response->setCache($options);
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ final class DateHelperTest extends CIUnitTestCase
|
||||
|
||||
public function testNowDefault()
|
||||
{
|
||||
$time = new DateTime();
|
||||
$this->assertCloseEnough(now(), time()); // close enough
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() . '/';
|
||||
|
@ -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() . '/';
|
||||
|
||||
|
@ -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() . '/';
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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 = [
|
||||
|
@ -328,7 +328,6 @@ class ViewTest extends CIUnitTestCase
|
||||
$view = new View($this->config, $this->viewsDir, $this->loader);
|
||||
|
||||
$view->setVar('testString', 'Hello World');
|
||||
$expected = "<p>Open</p>\n<h1>Hello World</h1>";
|
||||
|
||||
$content = $view->render('extend_include');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user