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

WordPressSearch::__construct()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.439
c 0
b 0
f 0
cc 6
eloc 12
nc 16
nop 1
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