Issues (16)

src/VObjects/Scalar/Integer.php (2 issues)

1
<?php
2
/**
3
 * This file is part of True Loaded.
4
 *
5
 * @link http://www.holbi.co.uk
6
 * @copyright Copyright (c) 2005 Holbi Group LTD
7
 *
8
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
12
13
namespace DBUnt1tled\VO\VObjects\Scalar;
14
15
use DBUnt1tled\VO\Exception\InvalidVOArgumentException;
16
use DBUnt1tled\VO\VObjects\ValueObject;
17
18
class Integer extends ValueObject
19
{
20
    /**
21
     * @param mixed $value
22
     * @param mixed ...$other
23
     * @throws \ReflectionException
24
     */
25 7
    public function guard($value, ...$other): void
26
    {
27 7
        parent::guard($value);
28 7
        if (!\is_int($value)) {
29 1
            throw new InvalidVOArgumentException('Value is invalid. Allowed type is integer', $value);
30
        }
31 6
    }
32
33
    /**
34
     * @param bool $bool
35
     * @return Integer
36
     * @throws \ReflectionException
37
     */
38 1
    public static function createFromBool(bool $bool): self
39
    {
40 1
        return new static((int)$bool);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new static((int)$bool) returns the type DBUnt1tled\VO\VObjects\Scalar\Integer which is incompatible with the documented return type integer.
Loading history...
41
    }
42
43
    /**
44
     * @param string $string
45
     * @return Integer
46
     * @throws \ReflectionException
47
     */
48 6
    public static function createFromString(string $string): self
49
    {
50 6
        if (filter_var($string, FILTER_VALIDATE_INT) !== false) {
51 4
            return new static((int)$string);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new static((int)$string) returns the type DBUnt1tled\VO\VObjects\Scalar\Integer which is incompatible with the documented return type integer.
Loading history...
52
        }
53 3
        throw new InvalidVOArgumentException('Value is invalid. Allowed type is integer, float, double, real', $string);
54
    }
55
}
56