Completed
Pull Request — master (#22)
by
unknown
03:40
created

FilterTrait::filter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Freshdesk\Resources\Traits;
4
5
/**
6
 * Create Trait
7
 *
8
 * @package Freshdesk\Resources\Traits
9
 */
10
trait FilterTrait
11
{
12
13
    /**
14
     * @param null $end string
15
     * @return string
16
     * @internal
17
     */
18
    abstract protected function endpoint($end = null);
19
20
    /**
21
     * @return \Freshdesk\Api
22
     * @internal
23
     */
24
    abstract protected function api();
25
26
    /**
27
     * Filter a resource
28
     *
29
     * Filter a resource by $query
30
     * Make sure to pass a valid $query string
31
     *
32
     * @api
33
     * @param string $query
34
     * @return array|null
35
     * @throws \Freshdesk\Exceptions\AccessDeniedException
36
     * @throws \Freshdesk\Exceptions\ApiException
37
     * @throws \Freshdesk\Exceptions\AuthenticationException
38
     * @throws \Freshdesk\Exceptions\ConflictingStateException
39
     * @throws \Freshdesk\Exceptions\NotFoundException
40
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
41
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
42
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
43
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
44
     * @throws \Freshdesk\Exceptions\ValidationException
45
     */
46
    public function filter(string $query)
47
    {
48
        $end = '/search'.$this->endpoint();
49
        $query = [
50
            'query' => '"'.$query.'"',
51
        ];
52
        return $this->api()->request('GET', $end, null, $query);
53
    }
54
}
55