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

IsMatchingRegex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 21
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 10 2
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