Completed
Push — master ( 071f6e...2ed909 )
by Seth
25:30
created

constructSearchDomains()   B

Complexity

Conditions 5
Paths 8

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 5
eloc 12
nc 8
nop 1
1
<?php
2
3
namespace smtech\StMarksSearch\WordPress;
4
5
use smtech\StMarksSearch\AbstractSearchDomain;
6
use smtech\StMarksSearch\AbstractSearchDomainFactory;
7
use smtech\StMarksSearch\WordPress\Pages\PagesSearch;
8
use smtech\StMarksSearch\WordPress\Posts\PostsSearch;
9
10
/**
11
 * A parent object for WordPress search domains
12
 *
13
 * @author Seth Battis <[email protected]>
14
 */
15
class WordPressSearchDomainFactory extends AbstractSearchDomainFactory
16
{
17
    const POSTS = 'posts';
18
    const PAGES = 'pages';
19
20
    /**
21
     * Construct a WordPress search domain: `$params` must contain a `url`
22
     * field with a valid URL to a WordPress blog
23
     *
24
     * @param mixed[string] $params
1 ignored issue
show
Documentation introduced by
The doc-type mixed[string] could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
25
     * @return AbstractSearchDomain[]
26
     */
27
    public static function constructSearchDomains($params)
28
    {
29
        $domains = [];
30
31
        $consumedParams = [self::POSTS, self::PAGES];
32
33
        /*
34
         * FIXME this is really meant to be "if they didn't specify something,
35
         *       assume they meant posts" -- not sure that this the best way of
36
         *       saying that, though
37
         */
38
        if (!isset($params['posts']) && !isset($params[self::PAGES])) {
39
            $params[self::PAGES] = true;
40
        }
41
42
        $params[self::POSTS] = static::forceBooleanParameter($params, self::POSTS);
43
        $params[self::PAGES] = static::forceBooleanParameter($params, self::PAGES);
44
45
        if ($params[self::POSTS]) {
46
            $domains[] = new PostsSearch(static::consumeParameters($params, $consumedParams));
47
        }
48
        if ($params[self::PAGES]) {
49
            $domains[] = new PagesSearch(static::consumeParameters($params, $consumedParams));
50
        }
51
52
        return $domains;
53
    }
54
}
55