Skip to content

Commit 7093a47

Browse files
committed
method names, visibility, return types
1 parent 066c03d commit 7093a47

File tree

6 files changed

+19
-26
lines changed

6 files changed

+19
-26
lines changed

system/Files/File.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ public function getSize()
7474
* Retrieve the file size by unit, calculated in IEC standards with 1024 as base value.
7575
*
7676
* @phpstan-param positive-int $precision
77-
*
78-
* @return false|int|string
7977
*/
80-
public function getSizeByUnitBinary(FileSizeUnit $unit = FileSizeUnit::B, int $precision = 3)
78+
public function getSizeByBinaryUnit(FileSizeUnit $unit = FileSizeUnit::B, int $precision = 3): int|string
8179
{
8280
return $this->getSizeByUnitInternal(1024, $unit, $precision);
8381
}
@@ -86,26 +84,24 @@ public function getSizeByUnitBinary(FileSizeUnit $unit = FileSizeUnit::B, int $p
8684
* Retrieve the file size by unit, calculated in metric standards with 1000 as base value.
8785
*
8886
* @phpstan-param positive-int $precision
89-
*
90-
* @return false|int|string
9187
*/
92-
public function getSizeByUnitMetric(FileSizeUnit $unit = FileSizeUnit::B, int $precision = 3)
88+
public function getSizeByMetricUnit(FileSizeUnit $unit = FileSizeUnit::B, int $precision = 3): int|string
9389
{
9490
return $this->getSizeByUnitInternal(1000, $unit, $precision);
9591
}
9692

9793
/**
9894
* Retrieve the file size by unit.
9995
*
100-
* @deprecated 4.6.0 Use getSizeByUnitBinary() or getSizeByUnitMetric() instead
96+
* @deprecated 4.6.0 Use getSizeByBinaryUnit() or getSizeByMetricUnit() instead
10197
*
10298
* @return false|int|string
10399
*/
104100
public function getSizeByUnit(string $unit = 'b')
105101
{
106102
return match (strtolower($unit)) {
107-
'kb' => $this->getSizeByUnitBinary(FileSizeUnit::KB),
108-
'mb' => $this->getSizeByUnitBinary(FileSizeUnit::MB),
103+
'kb' => $this->getSizeByBinaryUnit(FileSizeUnit::KB),
104+
'mb' => $this->getSizeByBinaryUnit(FileSizeUnit::MB),
109105
default => $this->getSize()
110106
};
111107
}
@@ -216,10 +212,7 @@ public function getDestination(string $destination, string $delimiter = '_', int
216212
return $destination;
217213
}
218214

219-
/**
220-
* @return false|int|string
221-
*/
222-
protected function getSizeByUnitInternal(int $fileSizeBase, FileSizeUnit $unit, int $precision)
215+
private function getSizeByUnitInternal(int $fileSizeBase, FileSizeUnit $unit, int $precision): int|string
223216
{
224217
$exponent = $unit->value;
225218
$divider = $fileSizeBase ** $exponent;

tests/system/Files/FileTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public function testGetSizeBinary(FileSizeUnit $unit): void
120120
$divider = 1024 ** $unit->value;
121121
$file = new File(SYSTEMPATH . 'Common.php');
122122
$size = number_format(filesize(SYSTEMPATH . 'Common.php') / $divider, 3);
123-
$this->assertSame($size, $file->getSizeByUnitBinary($unit));
123+
$this->assertSame($size, $file->getSizeByBinaryUnit($unit));
124124
}
125125

126126
public function testGetSizeBinaryBytes(): void
127127
{
128128
$file = new File(SYSTEMPATH . 'Common.php');
129129
$size = filesize(SYSTEMPATH . 'Common.php');
130-
$this->assertSame($size, $file->getSizeByUnitBinary(FileSizeUnit::B));
130+
$this->assertSame($size, $file->getSizeByBinaryUnit(FileSizeUnit::B));
131131
}
132132

133133
#[DataProvider('provideGetSizeData')]
@@ -136,14 +136,14 @@ public function testGetSizeMetric(FileSizeUnit $unit): void
136136
$divider = 1000 ** $unit->value;
137137
$file = new File(SYSTEMPATH . 'Common.php');
138138
$size = number_format(filesize(SYSTEMPATH . 'Common.php') / $divider, 3);
139-
$this->assertSame($size, $file->getSizeByUnitMetric($unit));
139+
$this->assertSame($size, $file->getSizeByMetricUnit($unit));
140140
}
141141

142142
public function testGetSizeMetricBytes(): void
143143
{
144144
$file = new File(SYSTEMPATH . 'Common.php');
145145
$size = filesize(SYSTEMPATH . 'Common.php');
146-
$this->assertSame($size, $file->getSizeByUnitMetric(FileSizeUnit::B));
146+
$this->assertSame($size, $file->getSizeByMetricUnit(FileSizeUnit::B));
147147
}
148148

149149
public function testThrowsExceptionIfNotAFile(): void

user_guide_src/source/changelogs/v4.6.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Deprecations
279279
- The ``Filters::getArguments()`` method has been deprecated. No longer used.
280280
- **File:**
281281
- The function ``getSizeByUnit()`` of ``File`` has been deprecated.
282-
Use either ``getSizeByUnitBinary()`` or ``getSizeByUnitMetric()`` instead.
282+
Use either ``getSizeByBinaryUnit()`` or ``getSizeByMetricUnit()`` instead.
283283

284284
**********
285285
Bugs Fixed

user_guide_src/source/libraries/files.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ the results in kibibytes or mebibytes, respectively:
6666

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

69-
getSizeByUnitBinary()
69+
getSizeByBinaryUnit()
7070
=====================
7171

7272
Returns the size of the file default in bytes. You can pass in different FileSizeUnit values as the first parameter to get
@@ -78,7 +78,7 @@ the amount of decimal places.
7878

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

81-
getSizeByUnitMetric()
81+
getSizeByMetricUnit()
8282
=====================
8383

8484
Returns the size of the file default in bytes. You can pass in different FileSizeUnit values as the first parameter to get

user_guide_src/source/libraries/files/017.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
use CodeIgniter\Files\FileSizeUnit;
44

5-
$bytes = $file->getSizeByUnitBinary(); // 256901
6-
$kibibytes = $file->getSizeByUnitBinary(FileSizeUnit::KB); // 250.880
7-
$mebibytes = $file->getSizeByUnitBinary(FileSizeUnit::MB); // 0.245
5+
$bytes = $file->getSizeByBinaryUnit(); // 256901
6+
$kibibytes = $file->getSizeByBinaryUnit(FileSizeUnit::KB); // 250.880
7+
$mebibytes = $file->getSizeByBinaryUnit(FileSizeUnit::MB); // 0.245

user_guide_src/source/libraries/files/018.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
use CodeIgniter\Files\FileSizeUnit;
44

5-
$bytes = $file->getSizeByUnitMetric(); // 256901
6-
$kilobytes = $file->getSizeByUnitMetric(FileSizeUnit::KB); // 256.901
7-
$megabytes = $file->getSizeByUnitMetric(FileSizeUnit::MB); // 0.256
5+
$bytes = $file->getSizeByMetricUnit(); // 256901
6+
$kilobytes = $file->getSizeByMetricUnit(FileSizeUnit::KB); // 256.901
7+
$megabytes = $file->getSizeByMetricUnit(FileSizeUnit::MB); // 0.256

0 commit comments

Comments
 (0)