Skip to content

Commit d6dbcc3

Browse files
committed
Adjust code to PHP 8.0
1 parent e8373de commit d6dbcc3

33 files changed

+1039
-213
lines changed

docs/examples.md

Lines changed: 866 additions & 9 deletions
Large diffs are not rendered by default.

spec/PlainNumberSpec.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ function it_can_be_created_from_float()
5454
$this->toNumber()->shouldBe(123.66);
5555
}
5656

57-
function it_can_be_created_from_numeric_string()
58-
{
59-
$this->beConstructedThrough('from', ['123.66']);
60-
61-
$this->toNumber()->shouldBe(123.66);
62-
}
63-
6457
function it_compares_int_with_numbers_just_like_scalars()
6558
{
6659
$this->beConstructedWith(new JustInteger(123));

src/NumberValue.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,44 @@ interface NumberValue extends Value, Numberable
77
// comparators
88

99
/**
10-
* @param int|float|numeric-string|Numberable $other
11-
* @return int {-1, 0, 1}
10+
* @param float|int|numeric-string|Numberable $other
11+
* @return int<-1,1>
1212
*/
13-
public function compare($other): int;
13+
public function compare(float|int|string|Numberable $other): int;
1414

1515
/**
16-
* @param int|float|numeric-string|Numberable $other
16+
* @param float|int|numeric-string|Numberable $other
1717
*/
18-
public function equals($other): bool;
18+
public function equals(float|int|string|Numberable $other): bool;
1919

2020
// basic math
2121

2222
/**
23-
* @param int|float|numeric-string|Numberable $other
23+
* @param float|int|numeric-string|Numberable $other
2424
*/
25-
public function add($other): NumberValue;
25+
public function add(float|int|string|Numberable $other): NumberValue;
2626

2727
/**
28-
* @param int|float|numeric-string|Numberable $other
28+
* @param float|int|numeric-string|Numberable $other
2929
*/
30-
public function subtract($other): NumberValue;
30+
public function subtract(float|int|string|Numberable $other): NumberValue;
3131

3232
/**
33-
* @param int|float|numeric-string|Numberable $other
33+
* @param float|int|numeric-string|Numberable $other
3434
*/
35-
public function multiply($other): NumberValue;
35+
public function multiply(float|int|string|Numberable $other): NumberValue;
3636

3737
/**
38-
* @param int|float|numeric-string|Numberable $other
38+
* @param float|int|numeric-string|Numberable $other
3939
*/
40-
public function divide($other): NumberValue;
40+
public function divide(float|int|string|Numberable $other): NumberValue;
4141

4242
public function abs(): NumberValue;
4343

4444
/**
45-
* @param int|float|numeric-string|Numberable $divider
45+
* @param float|int|numeric-string|Numberable $divider
4646
*/
47-
public function modulo($divider): NumberValue;
47+
public function modulo(float|int|string|Numberable $divider): NumberValue;
4848

4949
// rounding
5050

src/Numberable.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44

55
interface Numberable
66
{
7-
/**
8-
* @return int|float
9-
*/
10-
public function toNumber();
7+
public function toNumber(): float|int;
118
}

src/Numberable/Absolute.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77

88
final class Absolute implements Numberable
99
{
10-
private Numberable $numberable;
11-
12-
public function __construct(Numberable $numberable)
13-
{
14-
$this->numberable = $numberable;
10+
public function __construct(
11+
private Numberable $numberable,
12+
) {
1513
}
1614

17-
/** @return int|float */
18-
public function toNumber()
15+
public function toNumber(): float|int
1916
{
2017
return abs($this->numberable->toNumber());
2118
}

src/Numberable/Add.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66

77
final class Add implements Numberable
88
{
9-
private Numberable $leftTerm;
10-
private Numberable $rightTerm;
11-
12-
public function __construct(Numberable $leftTerm, Numberable $rightTerm)
13-
{
14-
$this->leftTerm = $leftTerm;
15-
$this->rightTerm = $rightTerm;
9+
public function __construct(
10+
private Numberable $leftTerm,
11+
private Numberable $rightTerm,
12+
) {
1613
}
1714

18-
/** @return int|float */
19-
public function toNumber()
15+
public function toNumber(): float|int
2016
{
2117
return $this->leftTerm->toNumber() + $this->rightTerm->toNumber();
2218
}

src/Numberable/Average.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@
99

1010
final class Average implements Numberable
1111
{
12-
/** @var Arrayable<Numberable> */
13-
private Arrayable $terms;
14-
15-
/** @param Arrayable<Numberable> $terms */
16-
public function __construct(Arrayable $terms)
17-
{
18-
$this->terms = $terms;
12+
public function __construct(
13+
/** @var Arrayable<Numberable> */
14+
private Arrayable $terms,
15+
) {
1916
}
2017

21-
/** @return int|float */
22-
public function toNumber()
18+
public function toNumber(): float|int
2319
{
2420
$terms = $this->terms->toArray();
2521
$count = count($terms);

src/Numberable/Calculate.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66

77
final class Calculate implements Numberable
88
{
9-
private Numberable $numberable;
109
/** @var callable(int|float):(int|float|Numberable) */
1110
private $formula;
1211

1312
/** @param callable(int|float):(int|float|Numberable) $formula */
14-
public function __construct(Numberable $numberable, callable $formula)
15-
{
16-
$this->numberable = $numberable;
13+
public function __construct(
14+
private Numberable $numberable,
15+
callable $formula,
16+
) {
1717
$this->formula = $formula;
1818
}
1919

20-
/** @return int|float */
21-
public function toNumber()
20+
public function toNumber(): float|int
2221
{
2322
$result = ($this->formula)($this->numberable->toNumber());
2423

src/Numberable/Ceil.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
final class Ceil implements Numberable
99
{
10-
private Numberable $numberable;
11-
12-
public function __construct(Numberable $numberable)
13-
{
14-
$this->numberable = $numberable;
10+
public function __construct(
11+
private Numberable $numberable,
12+
) {
1513
}
1614

1715
public function toNumber(): float

src/Numberable/CompareAsInt.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
final class CompareAsInt
88
{
9-
private int $direction;
10-
11-
private function __construct(int $direction)
12-
{
13-
$this->direction = $direction;
9+
private function __construct(
10+
private int $direction,
11+
) {
1412
}
1513

1614
public static function asc(): self

0 commit comments

Comments
 (0)