Skip to content

Commit 08d81be

Browse files
chore(autoloader): Dump autoloader
Signed-off-by: nextcloud-command <[email protected]>
1 parent 761075d commit 08d81be

File tree

170 files changed

+1433
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1433
-712
lines changed

brick/math/psalm-baseline.xml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="6.8.8@1361cd33008feb3ae2b4a93f1860e14e538ec8c2">
3+
<file src="src/BigInteger.php">
4+
<FalsableReturnStatement>
5+
<code><![CDATA[\hex2bin($hex)]]></code>
6+
</FalsableReturnStatement>
7+
<InvalidFalsableReturnType>
8+
<code><![CDATA[string]]></code>
9+
</InvalidFalsableReturnType>
10+
</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>
70+
</files>

brick/math/src/BigDecimal.php

Lines changed: 52 additions & 5 deletions
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();
@@ -58,19 +60,23 @@ protected static function from(BigNumber $number): static
5860
* Example: `(12345, 3)` will result in the BigDecimal `12.345`.
5961
*
6062
* @param BigNumber|int|float|string $value The unscaled value. Must be convertible to a BigInteger.
61-
* @param int $scale The scale of the number, positive or zero.
62-
*
63-
* @throws \InvalidArgumentException If the scale is negative.
63+
* @param int $scale The scale of the number. If negative, the scale will be set to zero
64+
* and the unscaled value will be adjusted accordingly.
6465
*
6566
* @psalm-pure
6667
*/
6768
public static function ofUnscaledValue(BigNumber|int|float|string $value, int $scale = 0) : BigDecimal
6869
{
70+
$value = (string) BigInteger::of($value);
71+
6972
if ($scale < 0) {
70-
throw new \InvalidArgumentException('The scale cannot be negative.');
73+
if ($value !== '0') {
74+
$value .= \str_repeat('0', -$scale);
75+
}
76+
$scale = 0;
7177
}
7278

73-
return new BigDecimal((string) BigInteger::of($value), $scale);
79+
return new BigDecimal($value, $scale);
7480
}
7581

7682
/**
@@ -535,6 +541,7 @@ public function negated() : BigDecimal
535541
return new BigDecimal(Calculator::get()->neg($this->value), $this->scale);
536542
}
537543

544+
#[Override]
538545
public function compareTo(BigNumber|int|float|string $that) : int
539546
{
540547
$that = BigNumber::of($that);
@@ -552,6 +559,7 @@ public function compareTo(BigNumber|int|float|string $that) : int
552559
return - $that->compareTo($this);
553560
}
554561

562+
#[Override]
555563
public function getSign() : int
556564
{
557565
return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
@@ -567,6 +575,33 @@ public function getScale() : int
567575
return $this->scale;
568576
}
569577

578+
/**
579+
* Returns the number of significant digits in the number.
580+
*
581+
* This is the number of digits to both sides of the decimal point, stripped of leading zeros.
582+
* The sign has no impact on the result.
583+
*
584+
* Examples:
585+
* 0 => 0
586+
* 0.0 => 0
587+
* 123 => 3
588+
* 123.456 => 6
589+
* 0.00123 => 3
590+
* 0.0012300 => 5
591+
*/
592+
public function getPrecision(): int
593+
{
594+
$value = $this->value;
595+
596+
if ($value === '0') {
597+
return 0;
598+
}
599+
600+
$length = \strlen($value);
601+
602+
return ($value[0] === '-') ? $length - 1 : $length;
603+
}
604+
570605
/**
571606
* Returns a string representing the integral part of this decimal number.
572607
*
@@ -609,18 +644,21 @@ public function hasNonZeroFractionalPart() : bool
609644
return $this->getFractionalPart() !== \str_repeat('0', $this->scale);
610645
}
611646

647+
#[Override]
612648
public function toBigInteger() : BigInteger
613649
{
614650
$zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0);
615651

616652
return self::newBigInteger($zeroScaleDecimal->value);
617653
}
618654

655+
#[Override]
619656
public function toBigDecimal() : BigDecimal
620657
{
621658
return $this;
622659
}
623660

661+
#[Override]
624662
public function toBigRational() : BigRational
625663
{
626664
$numerator = self::newBigInteger($this->value);
@@ -629,6 +667,7 @@ public function toBigRational() : BigRational
629667
return self::newBigRational($numerator, $denominator, false);
630668
}
631669

670+
#[Override]
632671
public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
633672
{
634673
if ($scale === $this->scale) {
@@ -638,24 +677,32 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U
638677
return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode);
639678
}
640679

680+
#[Override]
641681
public function toInt() : int
642682
{
643683
return $this->toBigInteger()->toInt();
644684
}
645685

686+
#[Override]
646687
public function toFloat() : float
647688
{
648689
return (float) (string) $this;
649690
}
650691

692+
/**
693+
* @return numeric-string
694+
*/
695+
#[Override]
651696
public function __toString() : string
652697
{
653698
if ($this->scale === 0) {
699+
/** @var numeric-string */
654700
return $this->value;
655701
}
656702

657703
$value = $this->getUnscaledValueWithLeadingZeros();
658704

705+
/** @var numeric-string */
659706
return \substr($value, 0, -$this->scale) . '.' . \substr($value, -$this->scale);
660707
}
661708

brick/math/src/BigInteger.php

Lines changed: 15 additions & 0 deletions
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,8 +1023,13 @@ public function toBytes(bool $signed = true) : string
10131023
return \hex2bin($hex);
10141024
}
10151025

1026+
/**
1027+
* @return numeric-string
1028+
*/
1029+
#[Override]
10161030
public function __toString() : string
10171031
{
1032+
/** @var numeric-string */
10181033
return $this->value;
10191034
}
10201035

brick/math/src/BigNumber.php

Lines changed: 8 additions & 2 deletions
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.
@@ -51,8 +52,9 @@ abstract class BigNumber implements \JsonSerializable
5152
* - strings containing a `.` character or using an exponential notation are returned as BigDecimal
5253
* - strings containing only digits with an optional leading `+` or `-` sign are returned as BigInteger
5354
*
54-
* @throws NumberFormatException If the format of the number is not valid.
55+
* @throws NumberFormatException If the format of the number is not valid.
5556
* @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
57+
* @throws RoundingNecessaryException If the value cannot be converted to an instance of the subclass without rounding.
5658
*
5759
* @psalm-pure
5860
*/
@@ -71,6 +73,9 @@ final public static function of(BigNumber|int|float|string $value) : static
7173
}
7274

7375
/**
76+
* @throws NumberFormatException If the format of the number is not valid.
77+
* @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
78+
*
7479
* @psalm-pure
7580
*/
7681
private static function _of(BigNumber|int|float|string $value) : BigNumber
@@ -163,7 +168,7 @@ private static function _of(BigNumber|int|float|string $value) : BigNumber
163168
/**
164169
* Overridden by subclasses to convert a BigNumber to an instance of the subclass.
165170
*
166-
* @throws MathException If the value cannot be converted.
171+
* @throws RoundingNecessaryException If the value cannot be converted.
167172
*
168173
* @psalm-pure
169174
*/
@@ -502,6 +507,7 @@ abstract public function toFloat() : float;
502507
*/
503508
abstract public function __toString() : string;
504509

510+
#[Override]
505511
final public function jsonSerialize() : string
506512
{
507513
return $this->__toString();

0 commit comments

Comments
 (0)