Completed
Push — master ( 1d790a...bb9b7d )
by Seth
02:11
created

WordPressSearch   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 27 6
1
<?php
2
3
namespace smtech\StMarksSearch\WordPress;
4
5
use smtech\StMarksSearch\RequireParameter;
6
use smtech\StMarksSearch\SearchEngine;
7
use smtech\StMarksSearch\WordPress\Pages\PagesSearch;
8
use smtech\StMarksSearch\WordPress\Posts\PostsSearch;
9
10
/**
11
 * A WordPress search engine
12
 *
13
 * @author Seth Battis <[email protected]>
14
 */
15
class WordPressSearch extends SearchEngine
16
{
17
    use RequireParameter;
18
19
    /**
20
     * Construct a WordPressSearch
21
     *
22
     * `$params` may contain boolean values for `posts` and `pages` -- if
23
     * neither are present, `posts` will default true.
24
     *
25
     * @param mixed[] $params
26
     */
27
    public function __construct($params)
28
    {
29
        /*
30
         * FIXME this is really meant to be "if they didn't specify something,
31
         *       assume they meant posts" -- not sure that this the best way of
32
         *       saying that, though
33
         */
34
        if (!isset($params['posts']) && !isset($params['pages'])) {
35
            $params['posts'] = true;
36
        }
37
38
        $params['posts'] = $this->forceBooleanParameter($params, 'posts');
39
        $params['pages'] = $this->forceBooleanParameter($params, 'pages');
40
41
        if (!isset($params['icon'])) {
42
            $params['icon'] = 'https://s.w.org/favicon.ico?2';
43
        }
44
45
        parent::__construct($params);
46
47
        if ($params['posts']) {
48
            $this->addDomain(new PostsSearch($params));
49
        }
50
        if ($params['pages']) {
51
            $this->addDomain(new PagesSearch($params));
52
        }
53
    }
54
}
55