Skip to content
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

refactor: fix Forge::processIndexes() for empty $this->fields #9330

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
14 changes: 8 additions & 6 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
@@ -32,9 +32,9 @@ class Forge
protected $db;

/**
* List of fields.
* List of fields in the form `[name => attributes]`
*
* @var array<string, array|string> [name => attributes]
* @var array<string, array<string, bool|string>|string>
*/
protected $fields = [];

@@ -1108,10 +1108,12 @@ public function processIndexes(string $table): bool
$fk = $this->foreignKeys;

if ($this->fields === []) {
$this->fields = array_flip(array_map(
static fn ($columnName) => $columnName->name,
$this->db->getFieldData($this->db->DBPrefix . $table)
));
$fieldData = $this->db->getFieldData($this->db->DBPrefix . $table);

$this->fields = array_combine(
array_map(static fn ($columnName) => $columnName->name, $fieldData),
array_fill(0, count($fieldData), [])
);
}

$fields = $this->fields;
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/assign.propertyType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 21 errors
# total 20 errors

parameters:
ignoreErrors:
@@ -7,11 +7,6 @@ parameters:
count: 1
path: ../../system/Controller.php

-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fields \(array\<string, array\|string\>\) does not accept array\<int\|string, int\<0, max\>\>\.$#'
count: 1
path: ../../system/Database/Forge.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:\$format \(''html''\|''json''\|''xml''\|null\) does not accept ''txt''\.$#'
count: 1
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/missingType.iterableValue.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 1687 errors
# total 1686 errors

parameters:
ignoreErrors:
@@ -1707,11 +1707,6 @@ parameters:
count: 1
path: ../../system/Database/Forge.php

-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fields type has no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Database/Forge.php

-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fkAllowActions type has no value type specified in iterable type array\.$#'
count: 1

Unchanged files with check annotations Beta

};
}
public function testNoFormatterJSON(): void

Check warning on line 137 in tests/system/API/ResponseTraitTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 2.8638s from 0.5000s limit to run CodeIgniter\\API\\ResponseTraitTest::testNoFormatterJSON
{
$this->formatter = null;
$controller = $this->makeController(
$this->assertSame(200, $this->handler->getHeight());
}
public function testImageCreation(): void

Check warning on line 356 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.8575s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageCreation
{
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
$this->assertSame(exif_imagetype($this->root . 'ci-logo.png'), IMAGETYPE_PNG);
}
public function testImageReorientLandscape(): void

Check warning on line 453 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5547s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientLandscape
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/landscape_' . $i . '.jpg';
}
}
public function testImageReorientPortrait(): void

Check warning on line 472 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5332s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientPortrait
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/portrait_' . $i . '.jpg';
$this->assertSame('', $this->getStreamFilterBuffer());
}
public function testRun(): void

Check warning on line 69 in tests/system/CLI/ConsoleTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.6520s from 0.5000s limit to run CodeIgniter\\CLI\\ConsoleTest::testRun
{
$this->initCLI();
$this->assertSame(0, Fabricator::getCount('giants'));
}
public function testUniqueSetsOutUniqueFieldValues(): void

Check warning on line 496 in tests/system/Test/FabricatorTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5048s from 0.5000s limit to run CodeIgniter\\Test\\FabricatorTest::testUniqueSetsOutUniqueFieldValues
{
$model = new class () extends Model {
protected $allowedFields = ['email'];
$this->assertNull($this->handler->getMetaData(self::$dummy));
}
public function testGetMetaData(): void

Check warning on line 35 in tests/system/Cache/Handlers/AbstractHandlerTestCase.php

GitHub Actions / CacheLive (8.2) / Cache Live Tests

Took 2.7494s from 0.5000s limit to run CodeIgniter\\Cache\\Handlers\\MemcachedHandlerTest::testGetMetaData
{
$time = Time::now()->getTimestamp();
$this->handler->save(self::$key1, 'value');
return $this->getStreamFilterBuffer();
}
public function testCreateDatabase(): void

Check warning on line 72 in tests/system/Commands/CreateDatabaseTest.php

GitHub Actions / DatabaseLive (8.2, MySQLi, 8.0) / tests

Took 3.9807s from 0.5000s limit to run CodeIgniter\\Commands\\CreateDatabaseTest::testCreateDatabase

Check warning on line 72 in tests/system/Commands/CreateDatabaseTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 3.0514s from 0.5000s limit to run CodeIgniter\\Commands\\CreateDatabaseTest::testCreateDatabase

Check warning on line 72 in tests/system/Commands/CreateDatabaseTest.php

GitHub Actions / DatabaseLive (8.2, Postgre, 8.0) / tests

Took 4.0381s from 0.5000s limit to run CodeIgniter\\Commands\\CreateDatabaseTest::testCreateDatabase

Check warning on line 72 in tests/system/Commands/CreateDatabaseTest.php

GitHub Actions / DatabaseLive (8.2, SQLite3, 8.0) / tests

Took 3.7270s from 0.5000s limit to run CodeIgniter\\Commands\\CreateDatabaseTest::testCreateDatabase

Check warning on line 72 in tests/system/Commands/CreateDatabaseTest.php

GitHub Actions / DatabaseLive (8.2, SQLSRV, 8.0) / tests

Took 4.4190s from 0.5000s limit to run CodeIgniter\\Commands\\CreateDatabaseTest::testCreateDatabase
{
if ($this->connection instanceof OCI8Connection) {
$this->markTestSkipped('Needs to run on non-OCI8 drivers.');
CLI::init();
}
public function testMigrateAllWithWithTwoNamespaces(): void

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, MySQLi, 8.0) / tests

Took 0.6205s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 2.1002s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, Postgre, 8.0) / tests

Took 0.6226s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, SQLite3, 8.0) / tests

Took 0.7954s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, SQLSRV, 8.0) / tests

Took 0.7997s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces
{
command('migrate --all');
$this->resetStreamFilterBuffer();
$this->forge->dropTable('', true);
}
public function testForeignKey(): void

Check warning on line 491 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 2.8507s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testForeignKey
{
$this->forge->dropTable('forge_test_invoices', true);
$this->forge->dropTable('forge_test_users', true);
$this->forge->dropTable('forge_test_1', true);
}
public function testSetKeyNames(): void

Check warning on line 1233 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0418s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testSetKeyNames
{
$this->forge->dropTable('forge_test_1', true);
$this->forge->dropTable('forge_test_users', true);
}
public function testProcessIndexes(): void

Check warning on line 1674 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.4443s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes
{
// make sure tables don't exist
$this->forge->dropTable('actions', true);
$this->assertSame('MySQLi', $this->getPrivateProperty($db1, 'DBDriver'));
}
public function testConnectWithFailover(): void

Check warning on line 97 in tests/system/Database/Live/ConnectTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0930s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ConnectTest::testConnectWithFailover
{
$this->tests['failover'][] = $this->tests;
unset($this->tests['failover'][0]['failover']);
$this->assertStringContainsString('upsertone@test.com', $sql);
}
public function testUpsertBatchWithQuery(): void

Check warning on line 714 in tests/system/Database/Live/UpsertTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.9183s from 0.5000s limit to run CodeIgniter\\Database\\Live\\UpsertTest::testUpsertBatchWithQuery
{
$this->forge = Database::forge($this->DBGroup);
protected $refresh = true;
public function testCreateAddsToDatabase(): void

Check warning on line 34 in tests/system/Database/Live/FabricatorLiveTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.9153s from 0.5000s limit to run CodeIgniter\\Database\\Live\\FabricatorLiveTest::testCreateAddsToDatabase
{
$fabricator = new Fabricator(UserModel::class);
$this->seeInDatabase('job', ['name' => 'Grocery Sales']);
}
public function testInsertBatch(): void

Check warning on line 52 in tests/system/Database/Live/InsertTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8528s from 0.5000s limit to run CodeIgniter\\Database\\Live\\InsertTest::testInsertBatch
{
$table = 'type_test';
#[Group('DatabaseLive')]
final class WhenWhenNotModelTest extends LiveModelTestCase
{
public function testWhenWithTrueCondition(): void

Check warning on line 25 in tests/system/Models/WhenWhenNotModelTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8439s from 0.5000s limit to run CodeIgniter\\Models\\WhenWhenNotModelTest::testWhenWithTrueCondition
{
$secondaryData = [
[
unset($_ENV['encryption.key'], $_SERVER['encryption.key']);
}
public function testGenerateKeyShowsEncodedKey(): void

Check warning on line 77 in tests/system/Commands/GenerateKeyTest.php

GitHub Actions / SeparateProcess (8.2) / tests

Took 3.4615s from 0.5000s limit to run CodeIgniter\\Commands\\GenerateKeyTest::testGenerateKeyShowsEncodedKey
{
command('key:generate --show');
$this->assertStringContainsString('hex2bin:', $this->getBuffer());