Skip to content

Commit 8064bbc

Browse files
committed
refactor: remove deprecated File::getSizeByUnit()
1 parent 7d3b00b commit 8064bbc

5 files changed

Lines changed: 6 additions & 52 deletions

File tree

‎docs/changelogs/v4.8.0.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ Release Date: Unreleased
172172
- `CodeIgniter\Security\Exceptions\SecurityException::forInvalidSameSite()`
173173
- `CodeIgniter\Session\Exceptions\SessionException::forInvalidSameSiteSetting()`
174174

175+
- **Files:** Removed the following deprecated method:
176+
- `CodeIgniter\Files\File::getSizeByUnit()` (deprecated since v4.6.0)
177+
175178
- **Filters:** Removed the following deprecated properties and methods:
176179
- `CodeIgniter\Filters\Filters::$arguments` (deprecated since v4.6.0)
177180
- `CodeIgniter\Filters\Filters::$argumentsClass` (deprecated since v4.6.0)

‎docs/libraries/file_collections.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ When your collection is complete, you can use `get()` to retrieve the final list
3434
```php
3535
<?php
3636

37+
use CodeIgniter\Files\FileSizeUnit;
38+
3739
echo 'My files: ' . implode(PHP_EOL, $files->get());
3840
echo 'I have ' . count($files) . ' files!';
3941

4042
foreach ($files as $file) {
41-
echo 'Moving ' . $file->getBasename() . ', ' . $file->getSizeByUnit('mb');
43+
echo 'Moving ' . $file->getBasename() . ', ' . $file->getSizeByBinaryUnit(FileSizeUnit::MB);
4244
$file->move(WRITEPATH . $file->getRandomName());
4345
}
4446
```

‎docs/libraries/files.md‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ $size = $file->getSize(); // 256901
5959

6060
A `RuntimeException` will be thrown if the file does not exist or an error occurs.
6161

62-
### getSizeByUnit()
63-
64-
!!! danger "Deprecated since version 4.6.0"
65-
66-
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:
67-
68-
```php
69-
$bytes = $file->getSizeByUnit(); // 256901
70-
$kilobytes = $file->getSizeByUnit('kb'); // 250.880
71-
$megabytes = $file->getSizeByUnit('mb'); // 0.245
72-
```
73-
74-
A `RuntimeException` will be thrown if the file does not exist or an error occurs.
75-
7662
### getSizeByBinaryUnit()
7763

7864
!!! success "Available from version 4.6.0"

‎system/Files/File.php‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,6 @@ public function getSizeByMetricUnit(FileSizeUnit $unit = FileSizeUnit::B, int $p
8888
return $this->getSizeByUnitInternal(1000, $unit, $precision);
8989
}
9090

91-
/**
92-
* Retrieve the file size by unit.
93-
*
94-
* @deprecated 4.6.0 Use getSizeByBinaryUnit() or getSizeByMetricUnit() instead
95-
*
96-
* @return false|int|string
97-
*/
98-
public function getSizeByUnit(string $unit = 'b')
99-
{
100-
return match (strtolower($unit)) {
101-
'kb' => $this->getSizeByBinaryUnit(FileSizeUnit::KB),
102-
'mb' => $this->getSizeByBinaryUnit(FileSizeUnit::MB),
103-
default => $this->getSize(),
104-
};
105-
}
106-
10791
/**
10892
* Attempts to determine the file extension based on the trusted
10993
* getType() method. If the mime type is unknown, will return null.

‎tests/system/Files/FileTest.php‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,6 @@ public function testCanAccessSplFileInfoMethods(): void
9393
$this->assertSame('file', $file->getType());
9494
}
9595

96-
public function testGetSizeReturnsKB(): void
97-
{
98-
$file = new File(SYSTEMPATH . 'Common.php');
99-
$size = number_format(filesize(SYSTEMPATH . 'Common.php') / 1024, 3);
100-
$this->assertSame($size, $file->getSizeByUnit('kb'));
101-
}
102-
103-
public function testGetSizeReturnsMB(): void
104-
{
105-
$file = new File(SYSTEMPATH . 'Common.php');
106-
$size = number_format(filesize(SYSTEMPATH . 'Common.php') / 1024 / 1024, 3);
107-
$this->assertSame($size, $file->getSizeByUnit('mb'));
108-
}
109-
110-
public function testGetSizeReturnsBytes(): void
111-
{
112-
$file = new File(SYSTEMPATH . 'Common.php');
113-
$size = filesize(SYSTEMPATH . 'Common.php');
114-
$this->assertSame($size, $file->getSizeByUnit('b'));
115-
}
116-
11796
#[DataProvider('provideGetSizeData')]
11897
public function testGetSizeBinary(FileSizeUnit $unit): void
11998
{

0 commit comments

Comments
 (0)