Skip to content

Commit

Permalink
Introduced N for numeric functions
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Jul 27, 2021
1 parent d95b1c7 commit 273a85d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/N.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Shovel;

class N {
// N::isIntLike('12') // true
// N::isIntLike(3.14) // true
// N::isIntLike(7) // true
// N::isIntLike('23.5') // false
// N::isIntLike([1, 2, 3]) // false
public static function isIntLike($n): bool
{
return is_int($n) || is_float($n) || (is_string($n) && intval($n) . '' === $n);
}

public static function toInt($n): ?int
{
return $n === null ? null : intval($n);
}
}

0 comments on commit 273a85d

Please sign in to comment.