Completed
Push — master ( 9c4346...4bd980 )
by Patrick
06:39
created

ODataParams   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 87
Duplicated Lines 9.2 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
dl 8
loc 87
rs 10
wmc 16
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
F __construct() 8 75 16

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
Best Practice introduced by
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']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
90