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

AbstractStringMatch   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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