From a3704a1df4e78e55d17b33b5e13ad9f45a4b6a69 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Mon, 13 Jan 2025 07:49:37 +0300 Subject: [PATCH 1/4] refactor: Fix phpstan codeigniter.frameworkExceptionInstance (#9389) --- tests/system/Debug/ExceptionsTest.php | 2 +- tests/system/DebugTraceableTraitTest.php | 2 +- .../codeigniter.frameworkExceptionInstance.neon | 13 ------------- utils/phpstan-baseline/loader.neon | 1 - 4 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 utils/phpstan-baseline/codeigniter.frameworkExceptionInstance.neon diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index 25601e1f39..86b4b061ff 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -124,7 +124,7 @@ final class ExceptionsTest extends CIUnitTestCase $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('There.', 404))); $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('This.', 167))); $this->assertSame([500, EXIT_CONFIG], $determineCodes(new ConfigException('This.'))); - $this->assertSame([500, EXIT_CONFIG], $determineCodes(new CastException('This.'))); + $this->assertSame([500, EXIT_CONFIG], $determineCodes(CastException::forInvalidInterface('This.'))); $this->assertSame([500, EXIT_DATABASE], $determineCodes(new DatabaseException('This.'))); } diff --git a/tests/system/DebugTraceableTraitTest.php b/tests/system/DebugTraceableTraitTest.php index 26161d8de6..611f3f3374 100644 --- a/tests/system/DebugTraceableTraitTest.php +++ b/tests/system/DebugTraceableTraitTest.php @@ -28,7 +28,7 @@ final class DebugTraceableTraitTest extends CIUnitTestCase { public function testFactoryInstanceReturnsWhereItIsRaised(): void { - $e1 = new FrameworkException('Hello.'); + $e1 = new FrameworkException('Hello.'); // @phpstan-ignore codeigniter.frameworkExceptionInstance $e2 = FrameworkException::forEnabledZlibOutputCompression(); $this->assertContainsEquals(DebugTraceableTrait::class, class_uses(FrameworkException::class)); diff --git a/utils/phpstan-baseline/codeigniter.frameworkExceptionInstance.neon b/utils/phpstan-baseline/codeigniter.frameworkExceptionInstance.neon deleted file mode 100644 index 9ffb6b9d3a..0000000000 --- a/utils/phpstan-baseline/codeigniter.frameworkExceptionInstance.neon +++ /dev/null @@ -1,13 +0,0 @@ -# total 2 errors - -parameters: - ignoreErrors: - - - message: '#^Instantiating CastException using new is not allowed\. Use one of its named constructors instead\.$#' - count: 1 - path: ../../tests/system/Debug/ExceptionsTest.php - - - - message: '#^Instantiating FrameworkException using new is not allowed\. Use one of its named constructors instead\.$#' - count: 1 - path: ../../tests/system/DebugTraceableTraitTest.php diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 1cf2cabd4e..966a2311fc 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -2,7 +2,6 @@ includes: - argument.type.neon - assign.propertyType.neon - codeigniter.cacheHandlerInstance.neon - - codeigniter.frameworkExceptionInstance.neon - codeigniter.getReassignArray.neon - codeigniter.modelArgumentInstanceof.neon - codeigniter.modelArgumentType.neon From d47a25850c2360387023164bd05222fb5e656c67 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Tue, 14 Jan 2025 06:42:27 +0300 Subject: [PATCH 2/4] chore: Fix phpunit deprecations (#9402) * refactor: Remove unknown option * refactor: Remove deprecated `CoversTrait` --- phpunit.xml.dist | 1 - tests/system/DebugTraceableTraitTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7464323e40..0e5c9e24f8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,6 @@ failOnWarning="true" cacheDirectory="build/.phpunit.cache"> diff --git a/tests/system/DebugTraceableTraitTest.php b/tests/system/DebugTraceableTraitTest.php index 611f3f3374..623bb65cbe 100644 --- a/tests/system/DebugTraceableTraitTest.php +++ b/tests/system/DebugTraceableTraitTest.php @@ -16,13 +16,11 @@ namespace CodeIgniter; use CodeIgniter\Exceptions\DebugTraceableTrait; use CodeIgniter\Exceptions\FrameworkException; use CodeIgniter\Test\CIUnitTestCase; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; /** * @internal */ -#[CoversClass(DebugTraceableTrait::class)] #[Group('Others')] final class DebugTraceableTraitTest extends CIUnitTestCase { From 8ea35826ccaaea5c3c85934c70767288693bac3f Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 17 Jan 2025 14:19:07 +0800 Subject: [PATCH 3/4] chore: fix wrong constraint in mergeable.yml --- .github/mergeable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/mergeable.yml b/.github/mergeable.yml index 122651b0a8..95766c23fc 100644 --- a/.github/mergeable.yml +++ b/.github/mergeable.yml @@ -13,7 +13,7 @@ mergeable: regex: '### PHP Version' - do: description must_include: - regex: '### CodeIgniter Version' + regex: '### CodeIgniter4 Version' - do: author must_include: regex: ^kenjis|lonnieezell|MGatner|michalsn|paulbalandan|samsonasik$ From 119330c56f764d65d1f69cf7fc4b2a9a62561ba2 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 17 Jan 2025 22:51:06 +0800 Subject: [PATCH 4/4] refactor: Use `strtolower` with `str_contains`/`str_**_with` as replacement for `stripos` (#9414) * Use `modernize_stripos` option * Fix impossible conditional in test --- .php-cs-fixer.dist.php | 12 +----------- system/Database/Forge.php | 2 +- system/Database/OCI8/Forge.php | 2 +- system/Database/Postgre/Forge.php | 2 +- system/Database/SQLSRV/Forge.php | 4 ++-- system/Database/SQLite3/Forge.php | 2 +- system/Helpers/form_helper.php | 14 +++++++------- system/Test/CIUnitTestCase.php | 2 +- system/Test/Fabricator.php | 4 ++-- tests/system/Cache/CacheFactoryTest.php | 4 ++-- .../method.alreadyNarrowedType.neon | 7 +------ 11 files changed, 20 insertions(+), 35 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c9c24c7a06..e9240c5909 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -40,17 +40,7 @@ $finder = Finder::create() ]); $overrides = [ - 'get_class_to_class_keyword' => true, - 'trailing_comma_in_multiline' => [ - 'after_heredoc' => true, - 'elements' => [ - 'arguments', - 'array_destructuring', - 'arrays', - 'match', - 'parameters', - ], - ], + 'modernize_strpos' => ['modernize_stripos' => true], ]; $options = [ diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 83cf1b88d9..6bf5748189 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -1061,7 +1061,7 @@ class Forge protected function _attributeAutoIncrement(array &$attributes, array &$field) { if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true - && stripos($field['type'], 'int') !== false + && str_contains(strtolower($field['type']), 'int') ) { $field['auto_increment'] = ' AUTO_INCREMENT'; } diff --git a/system/Database/OCI8/Forge.php b/system/Database/OCI8/Forge.php index 4b09372d77..f761045d97 100644 --- a/system/Database/OCI8/Forge.php +++ b/system/Database/OCI8/Forge.php @@ -184,7 +184,7 @@ class Forge extends BaseForge protected function _attributeAutoIncrement(array &$attributes, array &$field) { if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true - && stripos($field['type'], 'NUMBER') !== false + && str_contains(strtolower($field['type']), 'number') && version_compare($this->db->getVersion(), '12.1', '>=') ) { $field['auto_increment'] = ' GENERATED BY DEFAULT ON NULL AS IDENTITY'; diff --git a/system/Database/Postgre/Forge.php b/system/Database/Postgre/Forge.php index 704f3e5760..b0a38c90ed 100644 --- a/system/Database/Postgre/Forge.php +++ b/system/Database/Postgre/Forge.php @@ -154,7 +154,7 @@ class Forge extends BaseForge protected function _attributeType(array &$attributes) { // Reset field lengths for data types that don't support it - if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== false) { + if (isset($attributes['CONSTRAINT']) && str_contains(strtolower($attributes['TYPE']), 'int')) { $attributes['CONSTRAINT'] = null; } diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index f187b9981f..7b1da6e85b 100644 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -360,7 +360,7 @@ class Forge extends BaseForge protected function _attributeType(array &$attributes) { // Reset field lengths for data types that don't support it - if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== false) { + if (isset($attributes['CONSTRAINT']) && str_contains(strtolower($attributes['TYPE']), 'int')) { $attributes['CONSTRAINT'] = null; } @@ -412,7 +412,7 @@ class Forge extends BaseForge */ protected function _attributeAutoIncrement(array &$attributes, array &$field) { - if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true && stripos($field['type'], 'INT') !== false) { + if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true && str_contains(strtolower($field['type']), strtolower('INT'))) { $field['auto_increment'] = ' IDENTITY(1,1)'; } } diff --git a/system/Database/SQLite3/Forge.php b/system/Database/SQLite3/Forge.php index 03120dd7a0..31c2a7ed58 100644 --- a/system/Database/SQLite3/Forge.php +++ b/system/Database/SQLite3/Forge.php @@ -226,7 +226,7 @@ class Forge extends BaseForge if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true - && stripos($field['type'], 'int') !== false + && str_contains(strtolower($field['type']), 'int') ) { $field['type'] = 'INTEGER PRIMARY KEY'; $field['default'] = ''; diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index ae4505c265..7b89bb9ec1 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -49,10 +49,10 @@ if (! function_exists('form_open')) { $attributes = stringify_attributes($attributes); - if (stripos($attributes, 'method=') === false) { + if (! str_contains(strtolower($attributes), 'method=')) { $attributes .= ' method="post"'; } - if (stripos($attributes, 'accept-charset=') === false) { + if (! str_contains(strtolower($attributes), 'accept-charset=')) { $config = config(App::class); $attributes .= ' accept-charset="' . strtolower($config->charset) . '"'; } @@ -62,7 +62,7 @@ if (! function_exists('form_open')) { // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites $before = service('filters')->getFilters()['before']; - if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && str_contains($action, base_url()) && stripos($form, 'method="get"') === false) { + if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && str_contains($action, base_url()) && ! str_contains(strtolower($form), strtolower('method="get"'))) { $form .= csrf_field($csrfId ?? null); } @@ -223,11 +223,11 @@ if (! function_exists('form_textarea')) { } // Unsets default rows and cols if defined in extra field as array or string. - if ((is_array($extra) && array_key_exists('rows', $extra)) || (is_string($extra) && stripos(preg_replace('/\s+/', '', $extra), 'rows=') !== false)) { + if ((is_array($extra) && array_key_exists('rows', $extra)) || (is_string($extra) && str_contains(strtolower(preg_replace('/\s+/', '', $extra)), 'rows='))) { unset($defaults['rows']); } - if ((is_array($extra) && array_key_exists('cols', $extra)) || (is_string($extra) && stripos(preg_replace('/\s+/', '', $extra), 'cols=') !== false)) { + if ((is_array($extra) && array_key_exists('cols', $extra)) || (is_string($extra) && str_contains(strtolower(preg_replace('/\s+/', '', $extra)), 'cols='))) { unset($defaults['cols']); } @@ -248,7 +248,7 @@ if (! function_exists('form_multiselect')) { { $extra = stringify_attributes($extra); - if (stripos($extra, 'multiple') === false) { + if (! str_contains(strtolower($extra), strtolower('multiple'))) { $extra .= ' multiple="multiple"'; } @@ -305,7 +305,7 @@ if (! function_exists('form_dropdown')) { } $extra = stringify_attributes($extra); - $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : ''; + $multiple = (count($selected) > 1 && ! str_contains(strtolower($extra), 'multiple')) ? ' multiple="multiple"' : ''; $form = '