| @@ 17-28 (lines=12) @@ | ||
| 14 | * |
|
| 15 | * @return \Closure |
|
| 16 | */ |
|
| 17 | public static function add() |
|
| 18 | { |
|
| 19 | return function ($a, $b) { |
|
| 20 | if (!is_numeric($a)) { |
|
| 21 | throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to perform addition, not %s', is_object($a) ? get_class($a) : gettype($a))); |
|
| 22 | } |
|
| 23 | if (!is_numeric($b)) { |
|
| 24 | throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to perform addition, not %s', is_object($b) ? get_class($b) : gettype($b))); |
|
| 25 | } |
|
| 26 | return $a + $b; |
|
| 27 | }; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * Returns a closure that subtracts one number from another |
|
| @@ 35-46 (lines=12) @@ | ||
| 32 | * |
|
| 33 | * @return \Closure |
|
| 34 | */ |
|
| 35 | public static function sub() |
|
| 36 | { |
|
| 37 | return function ($a, $b) { |
|
| 38 | if (!is_numeric($a)) { |
|
| 39 | throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to perform subtraction, not %s', is_object($a) ? get_class($a) : gettype($a))); |
|
| 40 | } |
|
| 41 | if (!is_numeric($b)) { |
|
| 42 | throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to perform subtraction, not %s', is_object($b) ? get_class($b) : gettype($b))); |
|
| 43 | } |
|
| 44 | return $a - $b; |
|
| 45 | }; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Returns a closure that multiplies two numbers |
|
| @@ 53-64 (lines=12) @@ | ||
| 50 | * |
|
| 51 | * @return \Closure |
|
| 52 | */ |
|
| 53 | public static function mul() |
|
| 54 | { |
|
| 55 | return function ($a, $b) { |
|
| 56 | if (!is_numeric($a)) { |
|
| 57 | throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to perform multiplication, not %s', is_object($a) ? get_class($a) : gettype($a))); |
|
| 58 | } |
|
| 59 | if (!is_numeric($b)) { |
|
| 60 | throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to perform multiplication, not %s', is_object($b) ? get_class($b) : gettype($b))); |
|
| 61 | } |
|
| 62 | return $a * $b; |
|
| 63 | }; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Returns a closure that returns the smallest of two numbers |
|