-
Notifications
You must be signed in to change notification settings - Fork 0
/
Divide.php
41 lines (33 loc) · 860 Bytes
/
Divide.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace ExeQue\Remix\Mutate\Number\Math;
use ExeQue\Remix\Assert;
use ExeQue\Remix\Mutate\Number\NumberMutator;
/**
* Divides a number with a given divisor.
*
* @author Morten Harders <mmh@harders-it.dk>
*/
class Divide extends NumberMutator
{
private int|float $divisor;
/**
* @param float|int $divisor The divisor to divide with.
*/
public function __construct(float|int $divisor)
{
$this->divisor = $divisor;
Assert::notEq($divisor, 0, 'Divisor must not be 0.');
}
/**
* @param float|int $divisor The divisor to divide with.
*/
public static function make(float|int $divisor): self
{
return new self($divisor);
}
protected function mutateNumber(float|int $value): float|int
{
return $value / $this->divisor;
}
}