Completed
Pull Request — master (#5)
by
unknown
01:38
created

functions.php ➔ Assert()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 11

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 16
nop 5
dl 22
loc 22
rs 8.6737
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Terah\Assert;
4
5
    /**
6
     * Assert
7
     *
8
     * LICENSE
9
     *
10
     * This source file is subject to the new BSD license that is bundled
11
     * with this package in the file LICENSE.txt.
12
     * If you did not receive a copy of the license and are unable to
13
     * obtain it through the world-wide-web, please send an email
14
     * to [email protected] so I can send you a copy immediately.
15
     */
16
17
/**
18
 * Assert and Validate functions
19
 *
20
 * @author Terry Cullen <[email protected]>
21
 *
22
 */
23
24
/**
25
 * Instantiate and return an Assert object, set to @throw AssertionFailedException.
26
 *
27
 * @param mixed  $value
28
 * @param string $fieldName
29
 * @param int    $code
30
 * @param string $error
31
 * @param string $level
32
 * @return Assert
33
 */
34 View Code Duplication
function Assert($value, $fieldName='', $code=0, $error='', $level=Assert::WARNING)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
{
36
    $assert = new Assert($value);
37
    if ( $fieldName )
38
    {
39
        $assert->fieldName($fieldName);
40
    }
41
    if ( $code )
42
    {
43
        $assert->code($code);
44
    }
45
    if ( $error )
46
    {
47
        $assert->error($error);
48
    }
49
    if ( $level )
50
    {
51
        $assert->level($level);
52
    }
53
54
    return $assert;
55
}
56
57
/**
58
 * Instantiate and return an Assert object, set to @throw ValidationFailedException.
59
 *
60
 * @param mixed  $value
61
 * @param string $fieldName
62
 * @param int    $code
63
 * @param string $error
64
 * @param string $level
65
 * @return Assert
66
 */
67 View Code Duplication
function Validate($value, $fieldName='', $code=0, $error='', $level=Assert::WARNING)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
{
69
    $assert = new Assert($value);
70
    if ( $fieldName )
71
    {
72
        $assert->fieldName($fieldName);
73
    }
74
    if ( $code )
75
    {
76
        $assert->code($code);
77
    }
78
    if ( $error )
79
    {
80
        $assert->error($error);
81
    }
82
    if ( $level )
83
    {
84
        $assert->level($level);
85
    }
86
87
    $assert->setExceptionClass('Terah\Assert\ValidationFailedException');
88
    return $assert;
89
}