Completed
Push — master ( df948c...389d06 )
by Alexandre
01:21
created

Invalid   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 44
ccs 9
cts 11
cp 0.8182
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 3 1
A __constructor() 0 3 1
A value() 0 6 2
A isInvalid() 0 3 1
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2017 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Schema;
9
10
11
/**
12
 * A singleton that represents an invalid value.
13
 *
14
 * The purpose of this class is to provide an alternative to **null** for invalid values when **null** could be considered
15
 * valid. This class is not meant to be used outside of this library unless you are extended the schema somehow.
16
 */
17
class Invalid {
18
    private static $value;
19
20
    /**
21
     * Private constructor to enforce singleton.
22
     */
23
    private function __constructor() {
0 ignored issues
show
Coding Style introduced by
Method name "Invalid::__constructor" is invalid; only PHP magic methods should be prefixed with a double underscore
Loading history...
24
        // no-op
25
    }
26
27
    /**
28
     * Return the invalid value.
29
     *
30
     * @return Invalid Returns the invalid value.
31
     */
32 144
    public static function value() {
33 144
        if (self::$value === null) {
34 1
            self::$value = new Invalid();
35 1
        }
36 144
        return self::$value;
37
    }
38
39
    /**
40
     * Tests a value to see if it is invalid.
41
     *
42
     * @param mixed $value The value to test.
43
     * @return bool Returns **true** of the value is invalid or **false** otherwise.
44
     */
45 142
    public static function isInvalid($value) {
46 142
        return $value === self::value();
47
    }
48
49
    /**
50
     * Tests whether a value could be valid.
51
     *
52
     * Unlike {@link Invalid::inValid()} a value could still be invalid in some way even if this method returns true.
53
     *
54
     * @param mixed $value The value to test.
55
     * @return bool Returns **true** of the value could be invalid or **false** otherwise.
56
     */
57 144
    public static function isValid($value) {
58 144
        return $value !== self::value();
59
    }
60
}
61