Completed
Push — master ( 939f61...d39d6a )
by Todd
11s
created

Invalid::__constructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
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 142
    public static function value() {
33 142
        if (self::$value === null) {
34 1
            self::$value = new Invalid();
35
        }
36 142
        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 140
    public static function isInvalid($value) {
46 140
        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 142
    public static function isValid($value) {
58 142
        return $value !== self::value();
59
    }
60
}
61