Passed
Push — master ( f510e9...9822a2 )
by Paul
10:29
created

AbstractSearch   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
dl 0
loc 55
ccs 0
cts 25
cp 0
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A __construct() 0 5 1
A results() 0 3 1
A search() 0 10 3
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Database\Search;
4
5
abstract class AbstractSearch
6
{
7
    protected $db;
8
    protected $results;
9
10
    public function __construct()
11
    {
12
        global $wpdb;
13
        $this->db = $wpdb;
14
        $this->results = [];
15
    }
16
17
    /**
18
     * @return string
19
     */
20
    public function render()
21
    {
22
        return '';
23
    }
24
25
    /**
26
     * @return array
27
     */
28
    public function results()
29
    {
30
        return $this->results;
31
    }
32
33
    /**
34
     * @param string $searchTerm
35
     * @return static
36
     */
37
    public function search($searchTerm)
38
    {
39
        if (empty($searchTerm)) {
40
            $this->results = [];
41
        } elseif (is_numeric($searchTerm)) {
42
            $this->results = $this->searchById((int) $searchTerm);
43
        } else {
44
            $this->results = $this->searchByTerm($searchTerm);
45
        }
46
        return $this;
47
    }
48
49
    /**
50
     * @param int $searchId
51
     * @return array
52
     */
53
    abstract protected function searchById($searchId);
54
55
    /**
56
     * @param string $searchTerm
57
     * @return array
58
     */
59
    abstract protected function searchByTerm($searchTerm);
60
}
61