Skip to content

Commit 4df66fc

Browse files
Merge pull request #2131 from nextcloud/dependabot/composer/stable32/web-auth/webauthn-lib-4.9.2
[stable32] build(deps): Bump web-auth/webauthn-lib from 4.9.1 to 4.9.2
2 parents 01b28bb + 68f6da6 commit 4df66fc

File tree

171 files changed

+1456
-810
lines changed

Some content is hidden

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

171 files changed

+1456
-810
lines changed

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();

brick/math/src/BigRational.php

Lines changed: 12 additions & 1 deletion
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;
@@ -376,7 +387,7 @@ public function __toString() : string
376387
return $numerator;
377388
}
378389

379-
return $this->numerator . '/' . $this->denominator;
390+
return $numerator . '/' . $denominator;
380391
}
381392

382393
/**

brick/math/src/Exception/MathException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
/**
88
* Base class for all math exceptions.
99
*/
10-
class MathException extends \Exception
10+
class MathException extends \RuntimeException
1111
{
1212
}

0 commit comments

Comments
 (0)