Passed
Push — master ( 63b2c7...9fa2c5 )
by Baptiste
53s
created

AssertionChain   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 7 2
A not() 0 4 1
1
<?php declare(strict_types=1);
2
namespace Behapi\Assert;
3
4
use Assert\AssertionChain as Beberlei;
5
6
/**
7
 * PR needed while some PRs are not merged and released on upstream. :}
8
 *
9
 * @method AssertionChain empty(string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string is empty.
10
 * @method AssertionChain maxCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable does not have more than $count elements.
11
 * @method AssertionChain minCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable has at least $count elements.
12
 * @method AssertionChain notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars.
13
 * @method AssertionChain isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable.
14
 *
15
 * @link https://github.com/beberlei/assert/pull/264
16
 * @link https://github.com/beberlei/assert/pull/265
17
 * @link https://github.com/beberlei/assert/pull/266
18
 * @link https://github.com/beberlei/assert/pull/267
19
 */
20
class AssertionChain extends Beberlei
21
{
22
    /**
23
     * Perform a negative assertion.
24
     *
25
     * @var bool
26
     */
27
    private $not = false;
28
29
    public function __call($methodName, $args)
30
    {
31
        if ($this->not) {
32
            $methodName = "not{$methodName}";
33
        }
34
35
        return parent::__call($methodName, $args);
36
    }
37
38
    /**
39
     * Switch chain into negative mode.
40
     *
41
     * @return AssertionChain
42
     */
43
    public function not()
44
    {
45
        $this->not = true;
46
        return $this;
47
    }
48
}
49