Invalid   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 2 1
A __construct() 0 1 1
A value() 0 5 2
A isInvalid() 0 2 1
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2018 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
     * @noinspection PhpUnusedPrivateMethodInspection
24
     */
25 1
    private function __construct() {
26
        // no-op
27 1
    }
28
29
    /**
30
     * Return the invalid value.
31
     *
32
     * @return Invalid Returns the invalid value.
33
     */
34 234
    public static function value() {
35 234
        if (self::$value === null) {
36 1
            self::$value = new Invalid();
37
        }
38 234
        return self::$value;
39
    }
40
41
    /**
42
     * Tests a value to see if it is invalid.
43
     *
44
     * @param mixed $value The value to test.
45
     * @return bool Returns **true** of the value is invalid or **false** otherwise.
46
     */
47 232
    public static function isInvalid($value) {
48 232
        return $value === self::value();
49
    }
50
51
    /**
52
     * Tests whether a value could be valid.
53
     *
54
     * Unlike {@link Invalid::inValid()} a value could still be invalid in some way even if this method returns true.
55
     *
56
     * @param mixed $value The value to test.
57
     * @return bool Returns **true** of the value could be invalid or **false** otherwise.
58
     */
59 231
    public static function isValid($value) {
60 231
        return $value !== self::value();
61
    }
62
}
63