Completed
Push — master ( 256c3c...d8e20a )
by Karsten
01:47
created

AbstractStringMatch::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4
1
<?php
2
/**
3
 * Created by gerk on 29.11.17 08:38
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
 *
13
 *
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
abstract class AbstractStringMatch extends ParameterizedUnaryFunction
17
{
18
    /**
19
     * @param string|ValueHolder $search
20
     * @param bool|ValueHolder   $caseSensitive
21
     */
22 129
    public function __construct($search, $caseSensitive = true)
23
    {
24 129
        parent::__construct($search, $caseSensitive);
25 129
    }
26
27
    /**
28
     * This is where the real comparison happens
29
     *
30
     * @param string $needle
31
     * @param string $haystack
32
     *
33
     * @return bool
34
     */
35
    abstract public function match($needle, $haystack);
36
37 129
    public function __invoke($input)
38
    {
39 129
        if (! is_string($input)) {
40 32
            return false;
41
        }
42
43 97
        $search = $this->getValue();
44
45 97
        if (! is_string($search)) {
46 24
            return false;
47
        }
48
49 73
        if ((bool) $this->getValue2()) {
50 57
            return $this->match($search, $input);
51
        }
52
53 16
        return $this->match(strtolower($search), strtolower($input));
54
    }
55
}
56