SearchResource   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 56
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A searchPosts() 0 10 3
A searchUsers() 0 10 3
A searchHubs() 0 8 3
1
<?php
2
3
namespace Habrahabr\Api\Resources;
4
5
use Habrahabr\Api\Exception\IncorrectUsageException;
6
7
/**
8
 * Class SearchResource
9
 *
10
 * Ресурс работы с поиском
11
 *
12
 * @package Habrahabr\Api\Resources
13
 * @version 0.1.5
14
 * @author thematicmedia <[email protected]>
15
 * @link https://tmtm.ru/
16
 * @link https://habrahabr.ru/
17
 * @link https://github.com/thematicmedia/habrahabr_api
18
 *
19
 * For the full copyright and license information, please view the LICENSE
20
 * file that was distributed with this source code.
21
 */
22
class SearchResource extends AbstractResource implements ResourceInterface
23
{
24
    /**
25
     * Поиск произвольного запроса по постам
26
     *
27
     * @param string $q Поисковая фраза
28
     * @param int $page Номер страницы
29
     * @return array
30
     * @throws IncorrectUsageException
31
     */
32 2
    public function searchPosts($q, $page = 1)
33
    {
34 2
        if (!is_string($q) || empty($q)) {
35 1
            throw new IncorrectUsageException('Query must not be empty');
36
        }
37
38 1
        $this->checkPageNumber($page);
39
40 1
        return $this->adapter->get(sprintf('/search/posts/%s?page=%d', urlencode($q), $page));
41
    }
42
43
    /**
44
     * Поиск произвольного запроса по пользователям
45
     *
46
     * @param string $q Поисковая фраза
47
     * @param int $page Номер страницы
48
     * @return array
49
     * @throws IncorrectUsageException
50
     */
51 2
    public function searchUsers($q, $page = 1)
52
    {
53 2
        if (!is_string($q) || empty($q)) {
54 1
            throw new IncorrectUsageException('Query must not be empty');
55
        }
56
57 1
        $this->checkPageNumber($page);
58
59 1
        return $this->adapter->get(sprintf('/search/users/%s?page=%d', urlencode($q), $page));
60
    }
61
62
    /**
63
     * Поиск произвольного запроса по хабам
64
     *
65
     * @param string $q Поисковая фраза
66
     * @return array
67
     * @throws IncorrectUsageException
68
     */
69 2
    public function searchHubs($q)
70
    {
71 2
        if (!is_string($q) || empty($q)) {
72 1
            throw new IncorrectUsageException('Query must not be empty');
73
        }
74
75 1
        return $this->adapter->get(sprintf('/hubs/search/%s', urlencode($q)));
76
    }
77
}
78