Completed
Pull Request — master (#184)
by
unknown
01:50
created

Assert::thatNullOr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Assert
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * If you did not receive a copy of the license and are unable to
10
 * obtain it through the world-wide-web, please send an email
11
 * to [email protected] so I can send you a copy immediately.
12
 */
13
14
namespace Assert;
15
16
/**
17
 * AssertionChain factory
18
 */
19
abstract class Assert
20
{
21
    /** @var string */
22
    protected static $lazyAssertionExceptionClass = LazyAssertionException::class;
23
24
    /** @var string */
25
    protected static $assertionClass = Assertion::class;
26
27
    /**
28
     * Start validation on a value, returns {@link AssertionChain}
29
     *
30
     * The invocation of this method starts an assertion chain
31
     * that is happening on the passed value.
32
     *
33
     * @example
34
     *
35
     *  Assert::that($value)->notEmpty()->integer();
36
     *  Assert::that($value)->nullOr()->string()->startsWith("Foo");
37
     *
38
     * The assertion chain can be stateful, that means be careful when you reuse
39
     * it. You should never pass around the chain.
40
     *
41
     * @param mixed $value
42
     * @param string $defaultMessage
0 ignored issues
show
Documentation introduced by
Should the type for parameter $defaultMessage not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
43
     * @param string $defaultPropertyPath
0 ignored issues
show
Documentation introduced by
Should the type for parameter $defaultPropertyPath not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
44
     *
45
     * @return \Assert\AssertionChain
46
     */
47
    public static function that($value, $defaultMessage = null, $defaultPropertyPath = null)
48
    {
49
        return (new AssertionChain($value, $defaultMessage, $defaultPropertyPath))
50
            ->setAssertionClassName(static::$assertionClass)
51
        ;
52
    }
53
54
    /**
55
     * Start validation on a set of values, returns {@link AssertionChain}
56
     *
57
     * @param mixed $values
58
     * @param string $defaultMessage
0 ignored issues
show
Documentation introduced by
Should the type for parameter $defaultMessage not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
59
     * @param string $defaultPropertyPath
0 ignored issues
show
Documentation introduced by
Should the type for parameter $defaultPropertyPath not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
60
     *
61
     * @return \Assert\AssertionChain
62
     */
63
    public static function thatAll($values, $defaultMessage = null, $defaultPropertyPath = null)
64
    {
65
        return static::that($values, $defaultMessage, $defaultPropertyPath)->all();
66
    }
67
68
    /**
69
     * Start validation and allow NULL, returns {@link AssertionChain}
70
     *
71
     * @param mixed $value
72
     * @param string $defaultMessage
0 ignored issues
show
Documentation introduced by
Should the type for parameter $defaultMessage not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
73
     * @param string $defaultPropertyPath
0 ignored issues
show
Documentation introduced by
Should the type for parameter $defaultPropertyPath not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
74
     *
75
     * @return \Assert\AssertionChain
76
     */
77
    public static function thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null)
78
    {
79
        return static::that($value, $defaultMessage, $defaultPropertyPath)->nullOr();
80
    }
81
82
    /**
83
     * Create a lazy assertion object.
84
     *
85
     * @return \Assert\LazyAssertion
86
     */
87
    public static function lazy()
88
    {
89
        return (new LazyAssertion())
90
            ->setExceptionClass(static::$lazyAssertionExceptionClass)
91
        ;
92
    }
93
}
94