Skip to content

Commit 62a7edb

Browse files
committed
Refactor rounding methods and type hints in unit models
1 parent 19cd028 commit 62a7edb

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/Model/AbstractUnit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ abstract public static function getMapping(): array;
174174
/**
175175
* @param class-string<UnitInterface>|string $targetUnitClassOrType
176176
*/
177-
public function convert(string $targetUnitClassOrType): UnitInterface
177+
public function convert(string $targetUnitClassOrType): self
178178
{
179179
$mapping = static::getMapping();
180180

@@ -206,7 +206,7 @@ public function convert(string $targetUnitClassOrType): UnitInterface
206206
return new $targetUnitClassOrType($convertedValue);
207207
}
208208

209-
public function normalize(): UnitInterface
209+
public function normalize(): self
210210
{
211211
$mapping = static::getMapping();
212212

src/Model/Distance.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function floor(string $unitClass = Kilometer::class): self
7575
{
7676
return new self(
7777
$this->value->convert($unitClass)
78-
->round(0, \RoundingMode::TowardsZero)
78+
->floor()
7979
->convert(Meter::class)
8080
);
8181
}
@@ -84,7 +84,7 @@ public function ceil(string $unitClass = Kilometer::class): self
8484
{
8585
return new self(
8686
$this->value->convert($unitClass)
87-
->round(0, \RoundingMode::AwayFromZero)
87+
->ceil()
8888
->convert(Meter::class)
8989
);
9090
}
@@ -93,7 +93,7 @@ public function round(string $unitClass = Kilometer::class): self
9393
{
9494
return new self(
9595
$this->value->convert($unitClass)
96-
->round(0)
96+
->round()
9797
->convert(Meter::class)
9898
);
9999
}

src/Model/Duration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function floor(string $unitClass = Minute::class): self
276276
{
277277
return new self(
278278
$this->value->convert($unitClass)
279-
->round(0, \RoundingMode::TowardsZero)
279+
->floor()
280280
->convert(Second::class)
281281
);
282282
}
@@ -285,7 +285,7 @@ public function ceil(string $unitClass = Minute::class): self
285285
{
286286
return new self(
287287
$this->value->convert($unitClass)
288-
->round(0, \RoundingMode::AwayFromZero)
288+
->ceil()
289289
->convert(Second::class)
290290
);
291291
}
@@ -294,7 +294,7 @@ public function round(string $unitClass = Minute::class): self
294294
{
295295
return new self(
296296
$this->value->convert($unitClass)
297-
->round(0)
297+
->round()
298298
->convert(Second::class)
299299
);
300300
}

0 commit comments

Comments
 (0)