ValidateFloat   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A validate() 0 4 4
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp\Validation;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    XOOPS Project (https://xoops.org)
17
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 * @author       XOOPS Development Team
19
 */
20
21
/**
22
 * Class ValidateFloat
23
 */
24
class ValidateFloat extends Validator
25
{
26
    /**
27
     * Private
28
     * $text the string to validate
29
     */
30
    public $text;
31
    public $forceentry;
32
    //! A constructor.
33
34
    /**
35
     * Constructs a new ValidateFloat object subclass or Validator
36
     * @param string $text
37
     * @param bool   $forceentry
38
     */
39
    public function __construct(string $text, bool $forceentry = false)
40
    {
41
        $this->text       = $text;
42
        $this->forceentry = $forceentry;
43
        parent::__construct();
44
    }
45
46
    //! A manipulator
47
48
    /**
49
     * Validates a float number
50
     */
51
    public function validate()
52
    {
53
        if (!\is_float($this->text) && ('' !== $this->text && !$this->forceentry)) {
0 ignored issues
show
introduced by
The condition is_float($this->text) is always false.
Loading history...
54
            $this->setError(\_XHELP_MESSAGE_NOT_FLOAT);
55
        }
56
    }
57
}
58