Skip to content

Commit 6e9ffc2

Browse files
committed
Add #[Override] attributes
1 parent c04f0bd commit 6e9ffc2

8 files changed

+132
-1
lines changed

psalm-baseline.xml

+60-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.3.0@222dda8483516044c2ed7a4c3f197d7c9d6c3ddb">
2+
<files psalm-version="6.8.8@1361cd33008feb3ae2b4a93f1860e14e538ec8c2">
33
<file src="src/BigInteger.php">
44
<FalsableReturnStatement>
55
<code><![CDATA[\hex2bin($hex)]]></code>
@@ -8,4 +8,63 @@
88
<code><![CDATA[string]]></code>
99
</InvalidFalsableReturnType>
1010
</file>
11+
<file src="src/Exception/DivisionByZeroException.php">
12+
<ClassMustBeFinal>
13+
<code><![CDATA[DivisionByZeroException]]></code>
14+
</ClassMustBeFinal>
15+
</file>
16+
<file src="src/Exception/IntegerOverflowException.php">
17+
<ClassMustBeFinal>
18+
<code><![CDATA[IntegerOverflowException]]></code>
19+
</ClassMustBeFinal>
20+
</file>
21+
<file src="src/Exception/NegativeNumberException.php">
22+
<ClassMustBeFinal>
23+
<code><![CDATA[NegativeNumberException]]></code>
24+
</ClassMustBeFinal>
25+
</file>
26+
<file src="src/Exception/NumberFormatException.php">
27+
<ClassMustBeFinal>
28+
<code><![CDATA[NumberFormatException]]></code>
29+
</ClassMustBeFinal>
30+
</file>
31+
<file src="src/Exception/RoundingNecessaryException.php">
32+
<ClassMustBeFinal>
33+
<code><![CDATA[RoundingNecessaryException]]></code>
34+
</ClassMustBeFinal>
35+
</file>
36+
<file src="src/Internal/Calculator/BcMathCalculator.php">
37+
<ClassMustBeFinal>
38+
<code><![CDATA[BcMathCalculator]]></code>
39+
</ClassMustBeFinal>
40+
</file>
41+
<file src="src/Internal/Calculator/GmpCalculator.php">
42+
<ClassMustBeFinal>
43+
<code><![CDATA[GmpCalculator]]></code>
44+
</ClassMustBeFinal>
45+
</file>
46+
<file src="src/Internal/Calculator/NativeCalculator.php">
47+
<ClassMustBeFinal>
48+
<code><![CDATA[NativeCalculator]]></code>
49+
</ClassMustBeFinal>
50+
<InvalidOperand>
51+
<code><![CDATA[$a * $b]]></code>
52+
<code><![CDATA[$a * 1]]></code>
53+
<code><![CDATA[$a + $b]]></code>
54+
<code><![CDATA[$b * 1]]></code>
55+
<code><![CDATA[$b * 1]]></code>
56+
<code><![CDATA[$blockA * $blockB + $carry]]></code>
57+
<code><![CDATA[$blockA + $blockB]]></code>
58+
<code><![CDATA[$blockA + $blockB + $carry]]></code>
59+
<code><![CDATA[$blockA - $blockB]]></code>
60+
<code><![CDATA[$blockA - $blockB - $carry]]></code>
61+
<code><![CDATA[$carry]]></code>
62+
<code><![CDATA[$mul % $complement]]></code>
63+
<code><![CDATA[$mul - $value]]></code>
64+
<code><![CDATA[$nb - 1]]></code>
65+
<code><![CDATA[$sum += $complement]]></code>
66+
<code><![CDATA[($mul - $value) / $complement]]></code>
67+
<code><![CDATA[($nb - 1) * 10]]></code>
68+
</InvalidOperand>
69+
</file>
1170
</files>

src/BigDecimal.php

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Brick\Math\Exception\MathException;
99
use Brick\Math\Exception\NegativeNumberException;
1010
use Brick\Math\Internal\Calculator;
11+
use Override;
1112

1213
/**
1314
* Immutable, arbitrary-precision signed decimal numbers.
@@ -47,6 +48,7 @@ protected function __construct(string $value, int $scale = 0)
4748
/**
4849
* @psalm-pure
4950
*/
51+
#[Override]
5052
protected static function from(BigNumber $number): static
5153
{
5254
return $number->toBigDecimal();
@@ -535,6 +537,7 @@ public function negated() : BigDecimal
535537
return new BigDecimal(Calculator::get()->neg($this->value), $this->scale);
536538
}
537539

540+
#[Override]
538541
public function compareTo(BigNumber|int|float|string $that) : int
539542
{
540543
$that = BigNumber::of($that);
@@ -552,6 +555,7 @@ public function compareTo(BigNumber|int|float|string $that) : int
552555
return - $that->compareTo($this);
553556
}
554557

558+
#[Override]
555559
public function getSign() : int
556560
{
557561
return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
@@ -609,18 +613,21 @@ public function hasNonZeroFractionalPart() : bool
609613
return $this->getFractionalPart() !== \str_repeat('0', $this->scale);
610614
}
611615

616+
#[Override]
612617
public function toBigInteger() : BigInteger
613618
{
614619
$zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0);
615620

616621
return self::newBigInteger($zeroScaleDecimal->value);
617622
}
618623

624+
#[Override]
619625
public function toBigDecimal() : BigDecimal
620626
{
621627
return $this;
622628
}
623629

630+
#[Override]
624631
public function toBigRational() : BigRational
625632
{
626633
$numerator = self::newBigInteger($this->value);
@@ -629,6 +636,7 @@ public function toBigRational() : BigRational
629636
return self::newBigRational($numerator, $denominator, false);
630637
}
631638

639+
#[Override]
632640
public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
633641
{
634642
if ($scale === $this->scale) {
@@ -638,16 +646,19 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U
638646
return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode);
639647
}
640648

649+
#[Override]
641650
public function toInt() : int
642651
{
643652
return $this->toBigInteger()->toInt();
644653
}
645654

655+
#[Override]
646656
public function toFloat() : float
647657
{
648658
return (float) (string) $this;
649659
}
650660

661+
#[Override]
651662
public function __toString() : string
652663
{
653664
if ($this->scale === 0) {

src/BigInteger.php

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Brick\Math\Exception\NegativeNumberException;
1111
use Brick\Math\Exception\NumberFormatException;
1212
use Brick\Math\Internal\Calculator;
13+
use Override;
1314

1415
/**
1516
* An arbitrary-size integer.
@@ -42,6 +43,7 @@ protected function __construct(string $value)
4243
/**
4344
* @psalm-pure
4445
*/
46+
#[Override]
4547
protected static function from(BigNumber $number): static
4648
{
4749
return $number->toBigInteger();
@@ -856,6 +858,7 @@ public function testBit(int $n) : bool
856858
return $this->shiftedRight($n)->isOdd();
857859
}
858860

861+
#[Override]
859862
public function compareTo(BigNumber|int|float|string $that) : int
860863
{
861864
$that = BigNumber::of($that);
@@ -867,31 +870,37 @@ public function compareTo(BigNumber|int|float|string $that) : int
867870
return - $that->compareTo($this);
868871
}
869872

873+
#[Override]
870874
public function getSign() : int
871875
{
872876
return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
873877
}
874878

879+
#[Override]
875880
public function toBigInteger() : BigInteger
876881
{
877882
return $this;
878883
}
879884

885+
#[Override]
880886
public function toBigDecimal() : BigDecimal
881887
{
882888
return self::newBigDecimal($this->value);
883889
}
884890

891+
#[Override]
885892
public function toBigRational() : BigRational
886893
{
887894
return self::newBigRational($this, BigInteger::one(), false);
888895
}
889896

897+
#[Override]
890898
public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
891899
{
892900
return $this->toBigDecimal()->toScale($scale, $roundingMode);
893901
}
894902

903+
#[Override]
895904
public function toInt() : int
896905
{
897906
$intValue = (int) $this->value;
@@ -903,6 +912,7 @@ public function toInt() : int
903912
return $intValue;
904913
}
905914

915+
#[Override]
906916
public function toFloat() : float
907917
{
908918
return (float) $this->value;
@@ -1013,6 +1023,7 @@ public function toBytes(bool $signed = true) : string
10131023
return \hex2bin($hex);
10141024
}
10151025

1026+
#[Override]
10161027
public function __toString() : string
10171028
{
10181029
return $this->value;

src/BigNumber.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Brick\Math\Exception\MathException;
99
use Brick\Math\Exception\NumberFormatException;
1010
use Brick\Math\Exception\RoundingNecessaryException;
11+
use Override;
1112

1213
/**
1314
* Common interface for arbitrary-precision rational numbers.
@@ -506,6 +507,7 @@ abstract public function toFloat() : float;
506507
*/
507508
abstract public function __toString() : string;
508509

510+
#[Override]
509511
final public function jsonSerialize() : string
510512
{
511513
return $this->__toString();

src/BigRational.php

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Brick\Math\Exception\MathException;
99
use Brick\Math\Exception\NumberFormatException;
1010
use Brick\Math\Exception\RoundingNecessaryException;
11+
use Override;
1112

1213
/**
1314
* An arbitrarily large rational number.
@@ -57,6 +58,7 @@ protected function __construct(BigInteger $numerator, BigInteger $denominator, b
5758
/**
5859
* @psalm-pure
5960
*/
61+
#[Override]
6062
protected static function from(BigNumber $number): static
6163
{
6264
return $number->toBigRational();
@@ -320,16 +322,19 @@ public function simplified() : BigRational
320322
return new BigRational($numerator, $denominator, false);
321323
}
322324

325+
#[Override]
323326
public function compareTo(BigNumber|int|float|string $that) : int
324327
{
325328
return $this->minus($that)->getSign();
326329
}
327330

331+
#[Override]
328332
public function getSign() : int
329333
{
330334
return $this->numerator->getSign();
331335
}
332336

337+
#[Override]
333338
public function toBigInteger() : BigInteger
334339
{
335340
$simplified = $this->simplified();
@@ -341,32 +346,38 @@ public function toBigInteger() : BigInteger
341346
return $simplified->numerator;
342347
}
343348

349+
#[Override]
344350
public function toBigDecimal() : BigDecimal
345351
{
346352
return $this->numerator->toBigDecimal()->exactlyDividedBy($this->denominator);
347353
}
348354

355+
#[Override]
349356
public function toBigRational() : BigRational
350357
{
351358
return $this;
352359
}
353360

361+
#[Override]
354362
public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
355363
{
356364
return $this->numerator->toBigDecimal()->dividedBy($this->denominator, $scale, $roundingMode);
357365
}
358366

367+
#[Override]
359368
public function toInt() : int
360369
{
361370
return $this->toBigInteger()->toInt();
362371
}
363372

373+
#[Override]
364374
public function toFloat() : float
365375
{
366376
$simplified = $this->simplified();
367377
return $simplified->numerator->toFloat() / $simplified->denominator->toFloat();
368378
}
369379

380+
#[Override]
370381
public function __toString() : string
371382
{
372383
$numerator = (string) $this->numerator;

src/Internal/Calculator/BcMathCalculator.php

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Brick\Math\Internal\Calculator;
66

77
use Brick\Math\Internal\Calculator;
8+
use Override;
89

910
/**
1011
* Calculator implementation built around the bcmath library.
@@ -15,31 +16,37 @@
1516
*/
1617
class BcMathCalculator extends Calculator
1718
{
19+
#[Override]
1820
public function add(string $a, string $b) : string
1921
{
2022
return \bcadd($a, $b, 0);
2123
}
2224

25+
#[Override]
2326
public function sub(string $a, string $b) : string
2427
{
2528
return \bcsub($a, $b, 0);
2629
}
2730

31+
#[Override]
2832
public function mul(string $a, string $b) : string
2933
{
3034
return \bcmul($a, $b, 0);
3135
}
3236

37+
#[Override]
3338
public function divQ(string $a, string $b) : string
3439
{
3540
return \bcdiv($a, $b, 0);
3641
}
3742

43+
#[Override]
3844
public function divR(string $a, string $b) : string
3945
{
4046
return \bcmod($a, $b, 0);
4147
}
4248

49+
#[Override]
4350
public function divQR(string $a, string $b) : array
4451
{
4552
$q = \bcdiv($a, $b, 0);
@@ -48,16 +55,19 @@ public function divQR(string $a, string $b) : array
4855
return [$q, $r];
4956
}
5057

58+
#[Override]
5159
public function pow(string $a, int $e) : string
5260
{
5361
return \bcpow($a, (string) $e, 0);
5462
}
5563

64+
#[Override]
5665
public function modPow(string $base, string $exp, string $mod) : string
5766
{
5867
return \bcpowmod($base, $exp, $mod, 0);
5968
}
6069

70+
#[Override]
6171
public function sqrt(string $n) : string
6272
{
6373
return \bcsqrt($n, 0);

0 commit comments

Comments
 (0)