Completed
Push — master ( 3efda9...d6329d )
by Grzegorz
02:38
created

ControllerRequestAbstract::getController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ComicVine\Api\Controllers;
4
5
use ComicVine\Exceptions\EmptyControllerRequestUrl;
6
7
/**
8
 * Abstract base for ControllerRequest. Here
9
 * methods from ControllerRequest are assigned
10
 * and finally method call new controller.
11
 *
12
 * Class ControllerRequestAbstract
13
 *
14
 * @package grzgajda/comicvine-api
15
 * @author  Grzegorz Gajda <[email protected]>
16
 */
17
abstract class ControllerRequestAbstract
18
{
19
20
    /**
21
     * Filters for GET request.
22
     *
23
     * @var array
24
     */
25
    protected $enabledFilters
26
        = [
27
            'field_list' => true,
28
            'limit'      => false,
29
            'offset'     => false,
30
            'sort'       => false,
31
            'filter'     => false,
32
        ];
33
34
    /**
35
     * Set parameters which can be added to URL.
36
     *
37
     * @param bool|false $limit  The number of results to display per page.
38
     * @param bool|false $offset Return results starting with the object at the offset specified.
39
     * @param bool|false $sort   The result set can be sorted by the marked fields in the Fields section below.
40
     * @param bool|false $filter The result can be filtered by the marked fields in the Fields section below.
41
     *
42
     * @return $this
43
     */
44
    protected function setFilters($limit = false, $offset = false, $sort = false, $filter = false)
45
    {
46
        $this->enabledFilters = [
47
            'field_list' => true,
48
            'limit'      => $limit,
49
            'offset'     => $offset,
50
            'sort'       => $sort,
51
            'filter'     => $filter,
52
        ];
53
54
        return $this;
55
    }
56
57
    /**
58
     * Add url for this type of request.
59
     *
60
     * @param string $url Part of URL.
61
     *
62
     * @return \ComicVine\Api\Controllers\ControllerQuery
63
     * @throws \ComicVine\Exceptions\EmptyControllerRequestUrl
64
     */
65
    protected function setUrl($url)
66
    {
67
        return new ControllerQuery($this->enabledFilters, $url);
68
    }
69
70
}