AbstractStringMatch::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10
cc 4
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 205
    public function __construct($search, $caseSensitive = true)
23
    {
24 205
        parent::__construct($search, $caseSensitive);
25 205
    }
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 205
    public function __invoke($input)
38
    {
39 205
        if (! is_string($input)) {
40 48
            return false;
41
        }
42
43 157
        $search = $this->getValue();
44
45 157
        if (! is_string($search)) {
46 36
            return false;
47
        }
48
49 121
        if ((bool) $this->getValue2()) {
50 85
            return $this->match($search, $input);
51
        }
52
53 36
        return $this->match(strtolower($search), strtolower($input));
54
    }
55
}
56