-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathLong_.php
More file actions
35 lines (29 loc) · 784 Bytes
/
Long_.php
File metadata and controls
35 lines (29 loc) · 784 Bytes
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
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Types;
class Long_ extends Type implements PrimitiveValueInterface
{
const DEFAULT_VALUE = 0;
protected $nameInJava = 'long';
protected $nameInPHP = 'integer';
const MIN = PHP_INT_MIN;
const MAX = PHP_INT_MAX;
public static function isValid($value): bool
{
if (!is_scalar($value)) {
return false;
}
// Adjustment negative value for PHP problems
if ($value === static::MIN) {
$value++;
}
if (!ctype_digit((string) abs($value))) {
return false;
}
return $value >= static::MIN && $value <= static::MAX;
}
protected static function filter($value)
{
return (int) $value;
}
}