Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions docs/changelogs/v4.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion docs/libraries/file_collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ When your collection is complete, you can use `get()` to retrieve the final list
```php
<?php

use CodeIgniter\Files\FileSizeUnit;

echo 'My files: ' . implode(PHP_EOL, $files->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());
}
```
Expand Down
14 changes: 0 additions & 14 deletions docs/libraries/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 0 additions & 16 deletions system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 0 additions & 21 deletions tests/system/Files/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading