From 1e888a0b9d92d1b334feb492731d2596e7bef92b Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 19 Dec 2025 11:44:54 +0700 Subject: [PATCH 1/3] fix: null as an array offset is deprecated, use an empty string instead --- system/Autoloader/FileLocator.php | 22 +++++++++++----------- system/Autoloader/FileLocatorCached.php | 2 +- system/Autoloader/FileLocatorInterface.php | 18 +++++++++--------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index f67708a4e836..3d289040be8f 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -44,23 +44,23 @@ public function __construct(Autoloader $autoloader) * Attempts to locate a file by examining the name for a namespace * and looking through the PSR-4 namespaced files that we know about. * - * @param non-empty-string $file The relative file path or namespaced file to - * locate. If not namespaced, search in the app - * folder. - * @param non-empty-string|null $folder The folder within the namespace that we should - * look for the file. If $file does not contain - * this value, it will be appended to the namespace - * folder. - * @param string $ext The file extension the file should have. + * @param non-empty-string $file The relative file path or namespaced file to + * locate. If not namespaced, search in the app + * folder. + * @param non-empty-string $folder The folder within the namespace that we should + * look for the file. If $file does not contain + * this value, it will be appended to the namespace + * folder. + * @param string $ext The file extension the file should have. * * @return false|non-empty-string The path to the file, or false if not found. */ - public function locateFile(string $file, ?string $folder = null, string $ext = 'php') + public function locateFile(string $file, string $folder = '', string $ext = 'php') { $file = $this->ensureExt($file, $ext); // Clears the folder name if it is at the beginning of the filename - if ($folder !== null && str_starts_with($file, $folder)) { + if ($folder !== '' && str_starts_with($file, $folder)) { $file = substr($file, strlen($folder . '/')); } @@ -110,7 +110,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = ' // If we have a folder name, then the calling function // expects this file to be within that folder, like 'Views', // or 'libraries'. - if ($folder !== null && ! str_contains($path . $filename, '/' . $folder . '/')) { + if ($folder !== '' && ! str_contains($path . $filename, '/' . $folder . '/')) { $path .= trim($folder, '/') . '/'; } diff --git a/system/Autoloader/FileLocatorCached.php b/system/Autoloader/FileLocatorCached.php index 0aa267b2a84b..d6ad35885e83 100644 --- a/system/Autoloader/FileLocatorCached.php +++ b/system/Autoloader/FileLocatorCached.php @@ -161,7 +161,7 @@ public function listNamespaceFiles(string $prefix, string $path): array return $files; } - public function locateFile(string $file, ?string $folder = null, string $ext = 'php'): false|string + public function locateFile(string $file, string $folder = '', string $ext = 'php'): false|string { if (isset($this->cache['locateFile'][$file][$folder][$ext])) { return $this->cache['locateFile'][$file][$folder][$ext]; diff --git a/system/Autoloader/FileLocatorInterface.php b/system/Autoloader/FileLocatorInterface.php index 0422ec2519db..4988f4a21cee 100644 --- a/system/Autoloader/FileLocatorInterface.php +++ b/system/Autoloader/FileLocatorInterface.php @@ -23,18 +23,18 @@ interface FileLocatorInterface * Attempts to locate a file by examining the name for a namespace * and looking through the PSR-4 namespaced files that we know about. * - * @param non-empty-string $file The relative file path or namespaced file to - * locate. If not namespaced, search in the app - * folder. - * @param non-empty-string|null $folder The folder within the namespace that we should - * look for the file. If $file does not contain - * this value, it will be appended to the namespace - * folder. - * @param string $ext The file extension the file should have. + * @param non-empty-string $file The relative file path or namespaced file to + * locate. If not namespaced, search in the app + * folder. + * @param non-empty-string $folder The folder within the namespace that we should + * look for the file. If $file does not contain + * this value, it will be appended to the namespace + * folder. + * @param string $ext The file extension the file should have. * * @return false|non-empty-string The path to the file, or false if not found. */ - public function locateFile(string $file, ?string $folder = null, string $ext = 'php'); + public function locateFile(string $file, string $folder = '', string $ext = 'php'); /** * Examines a file and returns the fully qualified class name. From 54903ef2d7233d93b3ed2de858d59c81ae860dfb Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 19 Dec 2025 13:29:59 +0700 Subject: [PATCH 2/3] refactor: rules test --- tests/system/Validation/RulesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index 8bb6cab3ce77..14c99d5d9d78 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -779,7 +779,7 @@ public static function provideRequiredWithAndOtherRuleWithValueZero(): iterable } #[DataProvider('provideRequiredWithout')] - public function testRequiredWithout(?string $field, ?string $check, bool $expected): void + public function testRequiredWithout(string $field, ?string $check, bool $expected): void { $data = [ 'foo' => 'bar', @@ -802,8 +802,8 @@ public static function provideRequiredWithout(): iterable yield from [ ['nope', 'bars', false], ['foo', 'nope', true], - [null, null, false], - [null, 'foo', true], + ['', null, false], + ['', 'foo', true], ['foo', null, true], [ 'array.emptyField1', From 694ee32e5d7e7c953d7c9da03c5281c7fd04ab75 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 19 Dec 2025 20:30:39 +0700 Subject: [PATCH 3/3] refactor: locateFile refactor: locateFile --- system/Autoloader/FileLocator.php | 22 +++++++++++----------- system/Autoloader/FileLocatorCached.php | 14 ++++++++------ system/Autoloader/FileLocatorInterface.php | 18 +++++++++--------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 3d289040be8f..f67708a4e836 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -44,23 +44,23 @@ public function __construct(Autoloader $autoloader) * Attempts to locate a file by examining the name for a namespace * and looking through the PSR-4 namespaced files that we know about. * - * @param non-empty-string $file The relative file path or namespaced file to - * locate. If not namespaced, search in the app - * folder. - * @param non-empty-string $folder The folder within the namespace that we should - * look for the file. If $file does not contain - * this value, it will be appended to the namespace - * folder. - * @param string $ext The file extension the file should have. + * @param non-empty-string $file The relative file path or namespaced file to + * locate. If not namespaced, search in the app + * folder. + * @param non-empty-string|null $folder The folder within the namespace that we should + * look for the file. If $file does not contain + * this value, it will be appended to the namespace + * folder. + * @param string $ext The file extension the file should have. * * @return false|non-empty-string The path to the file, or false if not found. */ - public function locateFile(string $file, string $folder = '', string $ext = 'php') + public function locateFile(string $file, ?string $folder = null, string $ext = 'php') { $file = $this->ensureExt($file, $ext); // Clears the folder name if it is at the beginning of the filename - if ($folder !== '' && str_starts_with($file, $folder)) { + if ($folder !== null && str_starts_with($file, $folder)) { $file = substr($file, strlen($folder . '/')); } @@ -110,7 +110,7 @@ public function locateFile(string $file, string $folder = '', string $ext = 'php // If we have a folder name, then the calling function // expects this file to be within that folder, like 'Views', // or 'libraries'. - if ($folder !== '' && ! str_contains($path . $filename, '/' . $folder . '/')) { + if ($folder !== null && ! str_contains($path . $filename, '/' . $folder . '/')) { $path .= trim($folder, '/') . '/'; } diff --git a/system/Autoloader/FileLocatorCached.php b/system/Autoloader/FileLocatorCached.php index d6ad35885e83..28b7302f1dce 100644 --- a/system/Autoloader/FileLocatorCached.php +++ b/system/Autoloader/FileLocatorCached.php @@ -161,16 +161,18 @@ public function listNamespaceFiles(string $prefix, string $path): array return $files; } - public function locateFile(string $file, string $folder = '', string $ext = 'php'): false|string + public function locateFile(string $file, ?string $folder = null, string $ext = 'php'): false|string { - if (isset($this->cache['locateFile'][$file][$folder][$ext])) { - return $this->cache['locateFile'][$file][$folder][$ext]; + $folderKey = $folder ?? ''; + + if (isset($this->cache['locateFile'][$file][$folderKey][$ext])) { + return $this->cache['locateFile'][$file][$folderKey][$ext]; } - $files = $this->locator->locateFile($file, $folder, $ext); + $files = $this->locator->locateFile($file, $folderKey, $ext); - $this->cache['locateFile'][$file][$folder][$ext] = $files; - $this->cacheUpdated = true; + $this->cache['locateFile'][$file][$folderKey][$ext] = $files; + $this->cacheUpdated = true; return $files; } diff --git a/system/Autoloader/FileLocatorInterface.php b/system/Autoloader/FileLocatorInterface.php index 4988f4a21cee..0422ec2519db 100644 --- a/system/Autoloader/FileLocatorInterface.php +++ b/system/Autoloader/FileLocatorInterface.php @@ -23,18 +23,18 @@ interface FileLocatorInterface * Attempts to locate a file by examining the name for a namespace * and looking through the PSR-4 namespaced files that we know about. * - * @param non-empty-string $file The relative file path or namespaced file to - * locate. If not namespaced, search in the app - * folder. - * @param non-empty-string $folder The folder within the namespace that we should - * look for the file. If $file does not contain - * this value, it will be appended to the namespace - * folder. - * @param string $ext The file extension the file should have. + * @param non-empty-string $file The relative file path or namespaced file to + * locate. If not namespaced, search in the app + * folder. + * @param non-empty-string|null $folder The folder within the namespace that we should + * look for the file. If $file does not contain + * this value, it will be appended to the namespace + * folder. + * @param string $ext The file extension the file should have. * * @return false|non-empty-string The path to the file, or false if not found. */ - public function locateFile(string $file, string $folder = '', string $ext = 'php'); + public function locateFile(string $file, ?string $folder = null, string $ext = 'php'); /** * Examines a file and returns the fully qualified class name.