Completed
Push — master ( 7cb054...584ba8 )
by Tim
44:11 queued 26:38
created

Validate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 50
rs 10
wmc 6
lcom 0
cbo 1
1
<?php
2
/*
3
 * Copyright (c) Ouzo contributors, http://ouzoframework.org
4
 * This file is made available under the MIT License (view the LICENSE file for more information).
5
 */
6
namespace Ouzo\Utilities\Validator;
7
8
/**
9
 * Class Validate
10
 * @package Ouzo\Utilities\Validator
11
 */
12
class Validate
13
{
14
    /**
15
     * Checks if value is true, if not throws ValidateException with the given message.
16
     *
17
     * @param bool $value
18
     * @param string $message
19
     * @return bool
20
     * @throws ValidateException
21
     */
22
    public static function isTrue($value, $message = '')
23
    {
24
        if ($value !== true) {
25
            throw new ValidateException($message);
26
        }
27
        return true;
28
    }
29
30
    /**
31
     * Checks if value is a correct email address, otherwise throws ValidateException with the user given message.
32
     *
33
     * @param string $value
34
     * @param string $message
35
     * @return bool
36
     * @throws ValidateException
37
     */
38
    public static function isEmail($value, $message = '')
39
    {
40
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
41
            throw new ValidateException($message);
42
        }
43
        return true;
44
    }
45
46
    /**
47
     * Checks if value is not null, otherwise throws ValidateException with the user given message.
48
     *
49
     * @param mixed $value
50
     * @param string $message
51
     * @return bool
52
     * @throws ValidateException
53
     */
54
    public static function isNotNull($value, $message = '')
55
    {
56
        if ($value === null) {
57
            throw new ValidateException($message);
58
        }
59
        return true;
60
    }
61
}
62