Validate::email()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Helpers;
12
13
class Validate
14
{
15 8
    public static function string($string, array $options = [])
16
    {
17 8
        $options = array_merge([
18 8
            'minlength' => 1,
19 8
            'maxlength' => false,
20 8
        ], $options);
21
22 8
        return !empty($string) && is_string($string)
23 8
            && (strlen($string) >= $options['minlength'])
24 8
            && (($options['maxlength'] == false) || (strlen($string) <= $options['maxlength']));
25
    }
26
27 6
    public static function number($number, array $options = [])
28
    {
29 6
        $options = array_merge([
30 6
            'min' => false,
31 6
            'max' => false,
32 6
        ], $options);
33
34 6
        return is_numeric($number)
35 6
            && (($options['min'] === false) || ($number >= $options['min']))
36 6
            && (($options['max'] === false) || ($number <= $options['max']));
37
    }
38
39 3
    public static function email($email, array $options = [])
40
    {
41 3
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
42 1
            return true;
43
        } else {
44 2
            return false;
45
        }
46
    }
47
}
48