Skip to content

Commit 1235e35

Browse files
committed
Added PHP 8 support.
1 parent e984c4a commit 1235e35

File tree

11 files changed

+76
-74
lines changed

11 files changed

+76
-74
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ notifications:
44
language: php
55

66
php:
7-
- 5.6
8-
- 7.0
9-
- 7.1
10-
- 7.2
117
- 7.3
128
- 7.4
9+
- 8.0
1310

1411
env:
1512
matrix:

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
}
1515
},
1616
"require": {
17-
"php": "^5.5|^7",
17+
"php": "^7.3|^8",
1818
"scriptfusion/static-class": "^1"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.8",
22-
"mockery/mockery": "^1.3"
21+
"phpunit/phpunit": "^9",
22+
"mockery/mockery": "^1.4"
2323
},
2424
"scripts": {
2525
"test": "phpunit -c test"

src/Byte/ByteFormatter.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(UnitDecorator $unitDecorator = null)
5454
*
5555
* @return string Formatted bytes.
5656
*/
57-
public function format($bytes, $precision = null)
57+
public function format($bytes, $precision = null): string
5858
{
5959
// Use default precision when not specified.
6060
$precision === null && $precision = $this->getPrecision();
@@ -79,7 +79,7 @@ public function format($bytes, $precision = null)
7979
*
8080
* @return string Formatted number.
8181
*/
82-
private function formatValue($value, $precision)
82+
private function formatValue($value, $precision): string
8383
{
8484
$formatted = sprintf("%0.${precision}F", $value);
8585

@@ -108,7 +108,7 @@ private function formatValue($value, $precision)
108108
*
109109
* @return string sprintf() format.
110110
*/
111-
private function convertFormat($format)
111+
private function convertFormat($format): string
112112
{
113113
return str_replace(['%v', '%u'], ['%1$s', '%2$s'], $format);
114114
}
@@ -118,7 +118,7 @@ private function convertFormat($format)
118118
*
119119
* @return int Exponentiation base.
120120
*/
121-
public function getBase()
121+
public function getBase(): int
122122
{
123123
return $this->base;
124124
}
@@ -130,7 +130,7 @@ public function getBase()
130130
*
131131
* @return $this
132132
*/
133-
public function setBase($base)
133+
public function setBase($base): self
134134
{
135135
$this->base = $base|0;
136136

@@ -142,7 +142,7 @@ public function setBase($base)
142142
*
143143
* @return string Format specifier.
144144
*/
145-
public function getFormat()
145+
public function getFormat(): string
146146
{
147147
return $this->format;
148148
}
@@ -155,7 +155,7 @@ public function getFormat()
155155
*
156156
* @return $this
157157
*/
158-
public function setFormat($format)
158+
public function setFormat($format): self
159159
{
160160
$this->sprintfFormat = $this->convertFormat($this->format = "$format");
161161

@@ -167,7 +167,7 @@ public function setFormat($format)
167167
*
168168
* @return int Fractional digits.
169169
*/
170-
public function getPrecision()
170+
public function getPrecision(): int
171171
{
172172
return $this->precision;
173173
}
@@ -179,7 +179,7 @@ public function getPrecision()
179179
*
180180
* @return $this
181181
*/
182-
public function setPrecision($precision)
182+
public function setPrecision($precision): self
183183
{
184184
$this->precision = $precision|0;
185185

@@ -191,7 +191,7 @@ public function setPrecision($precision)
191191
*
192192
* @return $this
193193
*/
194-
public function enableAutomaticPrecision()
194+
public function enableAutomaticPrecision(): self
195195
{
196196
$this->automaticPrecision = true;
197197

@@ -203,7 +203,7 @@ public function enableAutomaticPrecision()
203203
*
204204
* @return $this
205205
*/
206-
public function disableAutomaticPrecision()
206+
public function disableAutomaticPrecision(): self
207207
{
208208
$this->automaticPrecision = false;
209209

@@ -216,7 +216,7 @@ public function disableAutomaticPrecision()
216216
* @return bool True if precision will be scaled automatically, otherwise
217217
* false.
218218
*/
219-
public function hasAutomaticPrecision()
219+
public function hasAutomaticPrecision(): bool
220220
{
221221
return $this->automaticPrecision;
222222
}
@@ -226,7 +226,7 @@ public function hasAutomaticPrecision()
226226
*
227227
* @return int Fixed exponent.
228228
*/
229-
public function getFixedExponent()
229+
public function getFixedExponent(): int
230230
{
231231
return $this->exponent;
232232
}
@@ -238,7 +238,7 @@ public function getFixedExponent()
238238
*
239239
* @return $this
240240
*/
241-
public function setFixedExponent($exponent)
241+
public function setFixedExponent($exponent): self
242242
{
243243
$this->exponent = $exponent|0;
244244

@@ -250,7 +250,7 @@ public function setFixedExponent($exponent)
250250
*
251251
* @return $this
252252
*/
253-
public function clearFixedExponent()
253+
public function clearFixedExponent(): self
254254
{
255255
$this->exponent = null;
256256

@@ -262,7 +262,7 @@ public function clearFixedExponent()
262262
*
263263
* @return bool True if a fixed exponent has been set, otherwise false.
264264
*/
265-
public function hasFixedExponent()
265+
public function hasFixedExponent(): bool
266266
{
267267
return $this->exponent !== null;
268268
}
@@ -272,7 +272,7 @@ public function hasFixedExponent()
272272
*
273273
* @return UnitDecorator
274274
*/
275-
public function getUnitDecorator()
275+
public function getUnitDecorator(): UnitDecorator
276276
{
277277
return $this->unitDecorator;
278278
}
@@ -284,7 +284,7 @@ public function getUnitDecorator()
284284
*
285285
* @return $this
286286
*/
287-
public function setUnitDecorator(UnitDecorator $decorator)
287+
public function setUnitDecorator(UnitDecorator $decorator): self
288288
{
289289
$this->unitDecorator = $decorator;
290290

src/Byte/Unit/NameDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class NameDecorator implements UnitDecorator
1313
Base::DECIMAL => ['kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zetta', 'yotta'],
1414
];
1515

16-
public function decorate($exponent, $base, $value)
16+
public function decorate($exponent, $base, $value): string
1717
{
1818
$suffix = $value === 1 ? 'byte' : 'bytes';
1919

src/Byte/Unit/SymbolDecorator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct($suffix = null)
2222
$this->setSuffix($suffix);
2323
}
2424

25-
public function decorate($exponent, $base, $value)
25+
public function decorate($exponent, $base, $value): string
2626
{
2727
if (($suffix = $this->suffix) === null) {
2828
switch ($base) {
@@ -43,12 +43,12 @@ public function decorate($exponent, $base, $value)
4343
return $this->prefixes[min($exponent, strlen($this->prefixes)) - 1] . $suffix;
4444
}
4545

46-
public function getPrefixes()
46+
public function getPrefixes(): string
4747
{
4848
return $this->prefixes;
4949
}
5050

51-
public function setPrefixes($prefixes)
51+
public function setPrefixes($prefixes): SymbolDecorator
5252
{
5353
$this->prefixes = (string)$prefixes;
5454

@@ -65,14 +65,14 @@ public function getSuffix()
6565
*
6666
* @return $this
6767
*/
68-
public function setSuffix($suffix)
68+
public function setSuffix($suffix): self
6969
{
7070
$this->suffix = $suffix;
7171

7272
return $this;
7373
}
7474

75-
public function alwaysShowUnit($show = true)
75+
public function alwaysShowUnit($show = true): SymbolDecorator
7676
{
7777
$this->alwaysShowUnit = (bool)$show;
7878

test/Integration/Byte/ByteFormatterTest.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<?php
22
namespace ScriptFUSIONTest\Integration\Byte;
33

4+
use PHPUnit\Framework\TestCase;
45
use ScriptFUSION\Byte\Base;
56
use ScriptFUSION\Byte\ByteFormatter;
67
use ScriptFUSION\Byte\Unit\SymbolDecorator;
78
use ScriptFUSION\Byte\Unit\UnitDecorator;
89

9-
final class ByteFormatterTest extends \PHPUnit_Framework_TestCase
10+
final class ByteFormatterTest extends TestCase
1011
{
1112
/** @var ByteFormatter */
1213
private $formatter;
1314

14-
protected function setUp()
15+
protected function setUp(): void
1516
{
1617
$this->formatter = (new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_NONE)))->setFormat('%v%u');
1718
}
1819

1920
/** @dataProvider provideBinaryIntegers */
20-
public function testBinaryFormat($integer, $formatted)
21+
public function testBinaryFormat($integer, $formatted): void
2122
{
2223
self::assertSame($formatted, $this->formatter->setBase(Base::BINARY)->format($integer));
2324
}
2425

25-
public function provideBinaryIntegers()
26+
public function provideBinaryIntegers(): array
2627
{
2728
return [
2829
[0, '0'],
@@ -48,12 +49,12 @@ public function provideBinaryIntegers()
4849
}
4950

5051
/** @dataProvider provideDecimalIntegers */
51-
public function testDecimalFormat($integer, $formatted)
52+
public function testDecimalFormat($integer, $formatted): void
5253
{
5354
self::assertSame($formatted, $this->formatter->setBase(Base::DECIMAL)->format($integer));
5455
}
5556

56-
public function provideDecimalIntegers()
57+
public function provideDecimalIntegers(): array
5758
{
5859
return [
5960
[0, '0'],
@@ -77,13 +78,13 @@ public function provideDecimalIntegers()
7778
}
7879

7980
/** @dataProvider providePrecisionIntegers */
80-
public function testPrecision($integer, $formatted)
81+
public function testPrecision($integer, $formatted): void
8182
{
8283
self::assertSame($formatted, $this->formatter->setPrecision(2)->format($integer));
8384
self::assertSame($formatted, $this->formatter->setPrecision(5)->format($integer, 2));
8485
}
8586

86-
public function providePrecisionIntegers()
87+
public function providePrecisionIntegers(): array
8788
{
8889
return [
8990
[0, '0'],
@@ -103,12 +104,12 @@ public function providePrecisionIntegers()
103104
}
104105

105106
/** @dataProvider provideFormats */
106-
public function testFormats($format, $formatted)
107+
public function testFormats($format, $formatted): void
107108
{
108109
self::assertSame($formatted, $this->formatter->setFormat($format)->format($this->formatter->getBase()));
109110
}
110111

111-
public function provideFormats()
112+
public function provideFormats(): array
112113
{
113114
return [
114115
['%v%u', '1K'],
@@ -122,15 +123,15 @@ public function provideFormats()
122123
}
123124

124125
/** @dataProvider provideFixedExponents */
125-
public function testFixedExponent($exponent, $bytes, $formatted)
126+
public function testFixedExponent($exponent, $bytes, $formatted): void
126127
{
127128
$this->formatter->setPrecision(8);
128129

129130
$this->formatter->setFixedExponent($exponent);
130131
self::assertSame($formatted, $this->formatter->format($bytes));
131132
}
132133

133-
public function provideFixedExponents()
134+
public function provideFixedExponents(): array
134135
{
135136
return [
136137
// TODO: Investigate rounding errors in following two cases.
@@ -157,14 +158,14 @@ public function provideFixedExponents()
157158
];
158159
}
159160

160-
public function testDisableAutomaticPrecision()
161+
public function testDisableAutomaticPrecision(): void
161162
{
162163
$this->formatter->disableAutomaticPrecision();
163164

164165
self::assertSame('512.50K', $this->formatter->format(0x80200, 2));
165166
}
166167

167-
public function testCustomUnitSequence()
168+
public function testCustomUnitSequence(): void
168169
{
169170
$formatter = (new ByteFormatter)->setUnitDecorator(
170171
\Mockery::mock(UnitDecorator::class)

0 commit comments

Comments
 (0)