Completed
Push — master ( 004515...b69bd3 )
by Karsten
01:42
created

IsMatchingRegex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 21
ccs 8
cts 8
cp 1
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 44
    public function __construct($regex)
20
    {
21 44
        parent::__construct($regex);
22 44
    }
23
24 44
    public function __invoke($input)
25
    {
26 44
        if (! is_scalar($input)) {
27 4
            return false;
28
        }
29
30 40
        $regex = $this->getValue();
31
32 40
        return preg_match($regex, $input) === 1;
33
    }
34
}
35