Completed
Push — master ( 4bd980...12d1e3 )
by Patrick
03:22
created

class.ODataParams.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
class ODataParams
3
{
4
    public $filter = false;
5
    public $expand = false;
6
    public $select = false;
7
    public $orderby = false;
8
    public $top = false;
9
    public $skip = false;
10
    public $count = false;
11
    public $search = false;
12
13
    function __construct($params)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
    {
15 View Code Duplication
        if(isset($params['filter']))
16
        {
17
            $this->filter = new \Data\Filter($params['filter']);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Data\Filter($params['filter']) of type object<Data\Filter> is incompatible with the declared type boolean of property $filter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18
        }
19
        else if(isset($params['$filter']))
20
        {
21
            $this->filter = new \Data\Filter($params['$filter']);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Data\Filter($params['$filter']) of type object<Data\Filter> is incompatible with the declared type boolean of property $filter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22
        }
23
24
        if(isset($params['$expand']))
25
        {
26
            $this->expand = explode(',',$params['$expand']);
0 ignored issues
show
Documentation Bug introduced by
It seems like explode(',', $params['$expand']) of type array is incompatible with the declared type boolean of property $expand.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
        }
28
29
        if(isset($params['select']))
30
        {
31
            $this->select = explode(',',$params['select']);
0 ignored issues
show
Documentation Bug introduced by
It seems like explode(',', $params['select']) of type array is incompatible with the declared type boolean of property $select.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        }
33
        else if(isset($params['$select']))
34
        {
35
            $this->select = explode(',',$params['$select']);
0 ignored issues
show
Documentation Bug introduced by
It seems like explode(',', $params['$select']) of type array is incompatible with the declared type boolean of property $select.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
        }
37
38
        if(isset($params['$orderby']))
39
        {
40
            $this->orderby = array();
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type boolean of property $orderby.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
            $orderby = explode(',',$params['$orderby']);
42
            $count = count($orderby);
43
            for($i = 0; $i < $count; $i++)
44
            {
45
                $exp = explode(' ',$orderby[$i]);
46
                if(count($exp) === 1)
47
                {
48
                    //Default to assending
49
                    $this->orderby[$exp[0]] = 1;
50
                }
51
                else
52
                {
53
                    switch($exp[1])
54
                    {
55
                        case 'asc':
56
                            $this->orderby[$exp[0]] = 1;
57
                            break;
58
                        case 'desc':
59
                            $this->orderby[$exp[0]] = -1;
60
                            break;
61
                        default:
62
                            throw new Exception('Unknown orderby operation');
63
                    }
64
                }
65
            }
66
        }
67
68
        if(isset($params['$top']))
69
        {
70
            $this->top = $params['$top'];
71
        }
72
73
        if(isset($params['$skip']))
74
        {
75
            $this->skip = $params['$skip'];
76
        }
77
78
        if(isset($params['$count']) && $params['$count'] === 'true')
79
        {
80
            $this->count = true;
81
        }
82
83
        if(isset($params['$seach']))
84
        {
85
            throw new Exception('Search not yet implemented');
86
        }
87
    }
88
}
89
?>
90