Completed
Push — master ( 1b12be...a9625e )
by Karsten
02:00
created

IsMatchingRegex::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
/**
3
 * Created by gerk on 30.11.17 05:44
4
 */
5
6
namespace PeekAndPoke\Component\Psi\Psi\Str;
7
8
use PeekAndPoke\Component\Psi\Functions\ParameterizedUnaryFunction;
9
use PeekAndPoke\Types\ValueHolder;
10
11
/**
12
 * @author Karsten J. Gerber <[email protected]>
13
 */
14
class IsMatchingRegex extends ParameterizedUnaryFunction
15
{
16
    /**
17
     * @param mixed|ValueHolder $regex
18
     */
19 40
    public function __construct($regex)
20
    {
21 40
        parent::__construct($regex);
22 40
    }
23
24 40
    public function __invoke($input)
25
    {
26 40
        if (! is_scalar($input)) {
27
            return false;
28
        }
29
30 40
        $regex = $this->getValue();
31
32 40
        return preg_match($regex, $input) === 1;
33
    }
34
}
35