Completed
Push — master ( d7eb82...e89277 )
by Patrick
03:09
created

ODataParams::__construct()   F

Complexity

Conditions 16
Paths 594

Size

Total Lines 75
Code Lines 37

Duplication

Lines 8
Ratio 10.67 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 16
eloc 37
c 1
b 0
f 1
nc 594
nop 1
dl 8
loc 75
rs 2.7066

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
class ODataParams
3
{
4
    /**
5
     * The ODataFilter or false if not set
6
     * @var false|Data\Filter
7
     */
8
    public $filter = false;
9
    /**
10
     * An array of properties to expand or false if not set
11
     * @var false|array
12
     */
13
    public $expand = false;
14
    /**
15
     * An array of properties to display or false if not set
16
     * @var false|array
17
     */
18
    public $select = false;
19
    /**
20
     * An array of properties to sort by or false if not set
21
     * @var false|array
22
     */
23
    public $orderby = false;
24
    /**
25
     * The number of results to display or false if not set
26
     * @var false|integer
27
     */
28
    public $top = false;
29
    /**
30
     * The number of results to skip or false if not set
31
     * @var false|integer
32
     */
33
    public $skip = false;
34
    /**
35
     * Display the count of results
36
     * @var boolean
37
     */
38
    public $count = false;
39
    public $search = false;
40
41
    public function __construct($params)
42
    {
43 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...
44
        {
45
            $this->filter = new \Data\Filter($params['filter']);
46
        }
47
        else if(isset($params['$filter']))
48
        {
49
            $this->filter = new \Data\Filter($params['$filter']);
50
        }
51
52
        if(isset($params['$expand']))
53
        {
54
            $this->expand = explode(',',$params['$expand']);
55
        }
56
57
        if(isset($params['select']))
58
        {
59
            $this->select = explode(',',$params['select']);
60
        }
61
        else if(isset($params['$select']))
62
        {
63
            $this->select = explode(',',$params['$select']);
64
        }
65
66
        if(isset($params['$orderby']))
67
        {
68
            $this->orderby = array();
69
            $orderby = explode(',',$params['$orderby']);
70
            $count = count($orderby);
71
            for($i = 0; $i < $count; $i++)
72
            {
73
                $exp = explode(' ',$orderby[$i]);
74
                if(count($exp) === 1)
75
                {
76
                    //Default to assending
77
                    $this->orderby[$exp[0]] = 1;
78
                }
79
                else
80
                {
81
                    switch($exp[1])
82
                    {
83
                        case 'asc':
84
                            $this->orderby[$exp[0]] = 1;
85
                            break;
86
                        case 'desc':
87
                            $this->orderby[$exp[0]] = -1;
88
                            break;
89
                        default:
90
                            throw new Exception('Unknown orderby operation');
91
                    }
92
                }
93
            }
94
        }
95
96
        if(isset($params['$top']))
97
        {
98
            $this->top = $params['$top'];
99
        }
100
101
        if(isset($params['$skip']))
102
        {
103
            $this->skip = $params['$skip'];
104
        }
105
106
        if(isset($params['$count']) && $params['$count'] === 'true')
107
        {
108
            $this->count = true;
109
        }
110
111
        if(isset($params['$seach']))
112
        {
113
            throw new Exception('Search not yet implemented');
114
        }
115
    }
116
}
117
?>
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...
118