Skip to content
Merged
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 src/DateTimeRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function __construct(
$interval = $this->to->diff($this->from);

$this->durationInSeconds
= (int) $interval->days * 86_400
= $interval->days * 86_400
+ $interval->h * 3_600
+ $interval->i * 60
+ $interval->s;
Expand Down
12 changes: 11 additions & 1 deletion src/UnsignedInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ final class UnsignedInt implements ToStringInterface, ComparableInterface
use ToStringTrait;
use StringComparableTrait;

/**
* @var int<0, max>
*/
private int $value;

public function __construct(
private int $value
int $value
) {
if ($value < 0 || $value > \PHP_INT_MAX) {
throw new InvalidTypeException('Invalid unsigned integer: ' . $value);
}

$this->value = $value;
}

/**
* @return int<0, max>
*/
public function getValue(): int
{
return $this->value;
Expand Down
4 changes: 4 additions & 0 deletions tools/cs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<exclude name="SlevomatCodingStandard.Classes.DisallowConstructorPropertyPromotion.DisallowedConstructorPropertyPromotion"/>
<exclude name="SlevomatCodingStandard.Classes.ForbiddenPublicProperty.ForbiddenPublicProperty"/>
</rule>
<!-- Promoted properties can't carry a ranged @var, which PHPStan needs for int<0, max> -->
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion">
<exclude-pattern>src/UnsignedInt.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" type="boolean" value="true"/>
Expand Down
Loading