Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ jobs:

- name: "Downgrade brick/math in lock file, to test compatibility with older versions"
run: |
composer update brick/math:"0.11.0"
composer update brick/math:"0.14.2"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@v3"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"php": "^8.2",
"brick/math": "^0.11 || ^0.12 || ^0.13 || ^0.14"
"brick/math": "^0.14.2 || ^0.15 || ^0.16 || ^0.17"
},
"require-dev": {
"captainhook/captainhook": "^5.25",
Expand Down
26 changes: 12 additions & 14 deletions src/Math/BrickMathCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
final class BrickMathCalculator implements CalculatorInterface
{
private const ROUNDING_MODE_MAP = [
RoundingMode::UNNECESSARY => BrickMathRounding::UNNECESSARY,
RoundingMode::UP => BrickMathRounding::UP,
RoundingMode::DOWN => BrickMathRounding::DOWN,
RoundingMode::CEILING => BrickMathRounding::CEILING,
RoundingMode::FLOOR => BrickMathRounding::FLOOR,
RoundingMode::HALF_UP => BrickMathRounding::HALF_UP,
RoundingMode::HALF_DOWN => BrickMathRounding::HALF_DOWN,
RoundingMode::HALF_CEILING => BrickMathRounding::HALF_CEILING,
RoundingMode::HALF_FLOOR => BrickMathRounding::HALF_FLOOR,
RoundingMode::HALF_EVEN => BrickMathRounding::HALF_EVEN,
RoundingMode::UNNECESSARY => BrickMathRounding::Unnecessary,
RoundingMode::UP => BrickMathRounding::Up,
RoundingMode::DOWN => BrickMathRounding::Down,
RoundingMode::CEILING => BrickMathRounding::Ceiling,
RoundingMode::FLOOR => BrickMathRounding::Floor,
RoundingMode::HALF_UP => BrickMathRounding::HalfUp,
RoundingMode::HALF_DOWN => BrickMathRounding::HalfDown,
RoundingMode::HALF_CEILING => BrickMathRounding::HalfCeiling,
RoundingMode::HALF_FLOOR => BrickMathRounding::HalfFloor,
RoundingMode::HALF_EVEN => BrickMathRounding::HalfEven,
];

public function add(NumberInterface $augend, NumberInterface ...$addends): NumberInterface
Expand Down Expand Up @@ -92,7 +92,7 @@
$quotient = BigDecimal::of($dividend->toString());

foreach ($divisors as $divisor) {
$quotient = $quotient->dividedBy($divisor->toString(), $scale, $brickRounding);

Check failure on line 95 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Parameter #2 $scale of method Brick\Math\BigDecimal::dividedBy() expects int<0, max>, int given.
}

if ($scale === 0) {
Expand All @@ -108,11 +108,11 @@
{
try {
/** @phpstan-ignore possiblyImpure.new */
return new IntegerObject((string) BigInteger::fromBase($value, $base));

Check failure on line 111 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Parameter #2 $base of static method Brick\Math\BigInteger::fromBase() expects int<2, 36>, int given.
} catch (MathException | \InvalidArgumentException $exception) {
throw new InvalidArgumentException(
$exception->getMessage(),

Check failure on line 114 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Possibly impure call to method Throwable::getMessage() in pure method Ramsey\Uuid\Math\BrickMathCalculator::fromBase().
(int) $exception->getCode(),

Check failure on line 115 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Possibly impure call to method Throwable::getCode() in pure method Ramsey\Uuid\Math\BrickMathCalculator::fromBase().
$exception
);
}
Expand All @@ -122,11 +122,11 @@
{
try {
/** @var non-empty-string */
return BigInteger::of($value->toString())->toBase($base);

Check failure on line 125 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Parameter #1 $base of method Brick\Math\BigInteger::toBase() expects int<2, 36>, int given.
} catch (MathException | \InvalidArgumentException $exception) {
throw new InvalidArgumentException(
$exception->getMessage(),

Check failure on line 128 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Possibly impure call to method Throwable::getMessage() in pure method Ramsey\Uuid\Math\BrickMathCalculator::toBase().
(int) $exception->getCode(),

Check failure on line 129 in src/Math/BrickMathCalculator.php

View workflow job for this annotation

GitHub Actions / Static analysis

Possibly impure call to method Throwable::getCode() in pure method Ramsey\Uuid\Math\BrickMathCalculator::toBase().
$exception
);
}
Expand All @@ -145,11 +145,9 @@

/**
* Maps ramsey/uuid rounding modes to those used by brick/math
*
* @return BrickMathRounding::*
*/
private function getBrickRoundingMode(int $roundingMode)
private function getBrickRoundingMode(int $roundingMode): BrickMathRounding
{
return self::ROUNDING_MODE_MAP[$roundingMode] ?? BrickMathRounding::UNNECESSARY;
return self::ROUNDING_MODE_MAP[$roundingMode] ?? BrickMathRounding::Unnecessary;
}
}
5 changes: 3 additions & 2 deletions src/Type/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public function toString(): string
{
/** @var numeric-string $microseconds */
$microseconds = sprintf('%06s', $this->microseconds->toString());
/** @var numeric-string $time */
$time = "{$this->seconds->toString()}.$microseconds";

/** @var numeric-string */
return "{$this->seconds->toString()}.$microseconds";
return $time;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Converter/Time/PhpTimeConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function testCalculateTimeReturnsArrayOfTimeSegments(): void

$converter = new PhpTimeConverter();

/** @var numeric-string $numericSeconds */
/** @var non-empty-string&numeric-string $numericSeconds */
$numericSeconds = (string) $seconds;

/** @var numeric-string $numericMicroseconds */
/** @var non-empty-string&numeric-string $numericMicroseconds */
$numericMicroseconds = (string) $microseconds;

$returned = $converter->calculateTime($numericSeconds, $numericMicroseconds);
Expand Down
4 changes: 3 additions & 1 deletion tests/Math/BrickMathCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public function testFromBaseThrowsException(): void
$calculator = new BrickMathCalculator();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"o" is not a valid character in base 16');
$this->expectExceptionMessageMatches(
'/(\"o\" is not a valid character in base 16\.|Character \"o\" is not valid in base 16\.)/'
);

$calculator->fromBase('foobar', 16);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,8 @@ public function test32BitMatch64BitForOneHourPeriod(): void
);

// Assert that the time matches
$usecAdd = BigDecimal::of($usec)->dividedBy('1000000', 14, RoundingMode::HALF_UP);
$testTime = BigDecimal::of($currentTime)->plus($usecAdd)->toScale(0, RoundingMode::DOWN);
$usecAdd = BigDecimal::of($usec)->dividedBy('1000000', 14, RoundingMode::HalfUp);
$testTime = BigDecimal::of($currentTime)->plus($usecAdd)->toScale(0, RoundingMode::Down);
$this->assertSame((string) $testTime, (string) $uuid64->getDateTime()->getTimestamp());
$this->assertSame((string) $testTime, (string) $uuid32->getDateTime()->getTimestamp());
}
Expand Down
Loading