Passed
Pull Request — master (#30)
by Baptiste
03:36 queued 01:24
created

Assert::notRegex()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 3
1
<?php
2
namespace Behapi\Tools;
3
4
use Webmozart\Assert\Assert as webmozart;
5
6
/**
7
 * Assert
8
 *
9
 * Use while https://github.com/webmozart/assert/pull/37 isn't merged
10
 *
11
 * @method static void nullOrNotContains($value, $subString, $message = '')
12
 * @method static void allContains($values, $subString, $message = '')
13
 */
14
class Assert extends webmozart
15
{
16
    public static function notContains($value, $subString, $message = '')
17
    {
18
        if (false === strpos($value, $subString)) {
19
            return;
20
        }
21
22
        static::reportInvalidArgument(sprintf(
23
            $message ?: 'Expected a value to not contain %2$s. Got: %s',
24
            static::valueToString($value),
25
            static::valueToString($subString)
26
        ));
27
    }
28
29
    public static function notRegex($value, $pattern, $message = '')
30
    {
31
        if (!preg_match($pattern, $value)) {
32
            return;
33
        }
34
35
        static::reportInvalidArgument(sprintf(
36
            $message ?: 'Expected a value to not match %s',
37
            static::valueToString($pattern)
38
        ));
39
    }
40
}
41