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

IsMatchingRegex::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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