TypeFloat::check()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 12
ccs 3
cts 3
cp 1
crap 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
class TypeFloat extends AbstractRule
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    protected const NAME = 'float';
20
21
    public function check($value): bool
22
    {
23
        // https://www.php.net/manual/en/function.is-float.php#117304
24
        if (! is_scalar($value)) {
25 2
            return false;
26
        }
27
28
        if ('double' === gettype($value)) {
29 2
            return true;
30
        }
31
32 2
        return preg_match('/^\\d+\\.\\d+$/', (string) $value) === 1;
33
    }
34
}
35