Completed
Push — v2 ( 40717e...aabbd0 )
by Beñat
02:45
created

Filter::setFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2014-2016 Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace BenatEspina\StackExchangeApiClient\Model;
13
14
/**
15
 * Class filter model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class Filter implements Model
20
{
21
    const FILTER_TYPES = ['invalid', 'safe', 'unsafe'];
22
23
    protected $filter;
24
    protected $filterType;
25
    protected $includedFields;
26
27
    public static function fromJson(array $data)
28
    {
29
        $instance = new self();
30
        $instance
31
            ->setFilter(array_key_exists('filter', $data) ? $data['filter'] : null)
32
            ->setFilterType(array_key_exists('filter_type', $data) ? $data['filter_type'] : null)
33
            ->setIncludedFields(array_key_exists('included_fields', $data) ? $data['included_fields'] : null);
34
35
        return $instance;
36
    }
37
38
    public static function fromProperties($filter, $filterType, array $includedFields)
39
    {
40
        $instance = new self();
41
        $instance
42
            ->setFilter($filter)
43
            ->setFilterType($filterType)
44
            ->setIncludedFields($includedFields);
45
46
        return $instance;
47
    }
48
49
    public function setFilter($filter)
50
    {
51
        $this->filter = $filter;
52
53
        return $this;
54
    }
55
56
    public function getFilter()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
57
    {
58
        return $this->filter;
59
    }
60
61
    public function setFilterType($filterType)
62
    {
63
        if (in_array($filterType, self::FILTER_TYPES, true)) {
64
            $this->filterType = $filterType;
65
        }
66
67
        return $this;
68
    }
69
70
    public function getFilterType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
71
    {
72
        return $this->filterType;
73
    }
74
75
    public function setIncludedFields(array $includedFields = [])
76
    {
77
        $this->includedFields = $includedFields;
78
79
        return $this;
80
    }
81
82
    public function getIncludedFields()
83
    {
84
        return $this->includedFields;
85
    }
86
}
87