From 8064bbcf38c9cd735163d2f428fddf234558e092 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 19 Nov 2026 21:42:56 +0800 Subject: [PATCH] refactor: remove deprecated `File::getSizeByUnit()` --- docs/changelogs/v4.8.0.md | 3 +++ docs/libraries/file_collections.md | 4 +++- docs/libraries/files.md | 14 -------------- system/Files/File.php | 16 ---------------- tests/system/Files/FileTest.php | 21 --------------------- 5 files changed, 6 insertions(+), 52 deletions(-) diff --git a/docs/changelogs/v4.8.0.md b/docs/changelogs/v4.8.0.md index bf8159d308e3..1a09d01aebfd 100644 --- a/docs/changelogs/v4.8.0.md +++ b/docs/changelogs/v4.8.0.md @@ -172,6 +172,9 @@ Release Date: Unreleased - `CodeIgniter\Security\Exceptions\SecurityException::forInvalidSameSite()` - `CodeIgniter\Session\Exceptions\SessionException::forInvalidSameSiteSetting()` +- **Files:** Removed the following deprecated method: + - `CodeIgniter\Files\File::getSizeByUnit()` (deprecated since v4.6.0) + - **Filters:** Removed the following deprecated properties and methods: - `CodeIgniter\Filters\Filters::$arguments` (deprecated since v4.6.0) - `CodeIgniter\Filters\Filters::$argumentsClass` (deprecated since v4.6.0) diff --git a/docs/libraries/file_collections.md b/docs/libraries/file_collections.md index 183735c1e340..0b89d5ad104a 100644 --- a/docs/libraries/file_collections.md +++ b/docs/libraries/file_collections.md @@ -34,11 +34,13 @@ When your collection is complete, you can use `get()` to retrieve the final list ```php get()); echo 'I have ' . count($files) . ' files!'; foreach ($files as $file) { - echo 'Moving ' . $file->getBasename() . ', ' . $file->getSizeByUnit('mb'); + echo 'Moving ' . $file->getBasename() . ', ' . $file->getSizeByBinaryUnit(FileSizeUnit::MB); $file->move(WRITEPATH . $file->getRandomName()); } ``` diff --git a/docs/libraries/files.md b/docs/libraries/files.md index bd37077fa483..f8b42675971c 100644 --- a/docs/libraries/files.md +++ b/docs/libraries/files.md @@ -59,20 +59,6 @@ $size = $file->getSize(); // 256901 A `RuntimeException` will be thrown if the file does not exist or an error occurs. -### getSizeByUnit() - -!!! danger "Deprecated since version 4.6.0" - -Returns the size of the file, in bytes by default. You can pass in either `'kb'` or `'mb'` as the first parameter to get the results in kibibytes or mebibytes, respectively: - -```php -$bytes = $file->getSizeByUnit(); // 256901 -$kilobytes = $file->getSizeByUnit('kb'); // 250.880 -$megabytes = $file->getSizeByUnit('mb'); // 0.245 -``` - -A `RuntimeException` will be thrown if the file does not exist or an error occurs. - ### getSizeByBinaryUnit() !!! success "Available from version 4.6.0" diff --git a/system/Files/File.php b/system/Files/File.php index 960e8be7b2b6..1ad84fbf3d28 100644 --- a/system/Files/File.php +++ b/system/Files/File.php @@ -88,22 +88,6 @@ public function getSizeByMetricUnit(FileSizeUnit $unit = FileSizeUnit::B, int $p return $this->getSizeByUnitInternal(1000, $unit, $precision); } - /** - * Retrieve the file size by unit. - * - * @deprecated 4.6.0 Use getSizeByBinaryUnit() or getSizeByMetricUnit() instead - * - * @return false|int|string - */ - public function getSizeByUnit(string $unit = 'b') - { - return match (strtolower($unit)) { - 'kb' => $this->getSizeByBinaryUnit(FileSizeUnit::KB), - 'mb' => $this->getSizeByBinaryUnit(FileSizeUnit::MB), - default => $this->getSize(), - }; - } - /** * Attempts to determine the file extension based on the trusted * getType() method. If the mime type is unknown, will return null. diff --git a/tests/system/Files/FileTest.php b/tests/system/Files/FileTest.php index b27c6b12c6da..b4e9e0173b03 100644 --- a/tests/system/Files/FileTest.php +++ b/tests/system/Files/FileTest.php @@ -93,27 +93,6 @@ public function testCanAccessSplFileInfoMethods(): void $this->assertSame('file', $file->getType()); } - public function testGetSizeReturnsKB(): void - { - $file = new File(SYSTEMPATH . 'Common.php'); - $size = number_format(filesize(SYSTEMPATH . 'Common.php') / 1024, 3); - $this->assertSame($size, $file->getSizeByUnit('kb')); - } - - public function testGetSizeReturnsMB(): void - { - $file = new File(SYSTEMPATH . 'Common.php'); - $size = number_format(filesize(SYSTEMPATH . 'Common.php') / 1024 / 1024, 3); - $this->assertSame($size, $file->getSizeByUnit('mb')); - } - - public function testGetSizeReturnsBytes(): void - { - $file = new File(SYSTEMPATH . 'Common.php'); - $size = filesize(SYSTEMPATH . 'Common.php'); - $this->assertSame($size, $file->getSizeByUnit('b')); - } - #[DataProvider('provideGetSizeData')] public function testGetSizeBinary(FileSizeUnit $unit): void {