Completed
Push — master ( ef8414...a67d49 )
by Richard
10s
created

Assert::that()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 9.4285
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 = 'Assert\LazyAssertionException';
23
24
    /** @var string */
25
    protected static $assertionClass = 'Assert\Assertion';
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
        $assertionChain = new AssertionChain($value, $defaultMessage, $defaultPropertyPath);
50
        return $assertionChain
51
            ->setAssertionClassName(static::$assertionClass)
52
        ;
53
    }
54
55
    /**
56
     * Start validation on a set of values, returns {@link AssertionChain}
57
     *
58
     * @param mixed $values
59
     * @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...
60
     * @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...
61
     *
62
     * @return \Assert\AssertionChain
63
     */
64
    public static function thatAll($values, $defaultMessage = null, $defaultPropertyPath = null)
65
    {
66
        return static::that($values, $defaultMessage, $defaultPropertyPath)->all();
67
    }
68
69
    /**
70
     * Start validation and allow NULL, returns {@link AssertionChain}
71
     *
72
     * @param mixed $value
73
     * @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...
74
     * @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...
75
     *
76
     * @return \Assert\AssertionChain
77
     */
78
    public static function thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null)
79
    {
80
        return static::that($value, $defaultMessage, $defaultPropertyPath)->nullOr();
81
    }
82
83
    /**
84
     * Create a lazy assertion object.
85
     *
86
     * @return \Assert\LazyAssertion
87
     */
88
    public static function lazy()
89
    {
90
        $lazyAssertion = new LazyAssertion();
91
        return $lazyAssertion
92
            ->setExceptionClass(static::$lazyAssertionExceptionClass)
93
        ;
94
    }
95
}
96