GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AdapterArrayObject::init()   C
last analyzed

Complexity

Conditions 10
Paths 256

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 6.1333
c 0
b 0
f 0
cc 10
nc 256
nop 0

How to fix   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
/**
3
 * ZfTable ( Module for Zend Framework 2)
4
 *
5
 * @copyright Copyright (c) 2013 Piotr Duda [email protected]
6
 * @license   MIT License
7
 */
8
9
namespace ZfTable\Params;
10
11
use ZfTable\Params\AbstractAdapter;
12
use ZfTable\Params\AdapterInterface;
13
use ZfTable\Table\Exception;
14
15
class AdapterArrayObject extends AbstractAdapter implements AdapterInterface, \Zend\Stdlib\InitializableInterface
16
{
17
18
    /**
19
     *
20
     * @var \ArrayObject | \Zend\Stdlib\ArrayObject
21
     */
22
    protected $object;
23
24
    /**
25
     *
26
     * @var int
27
     */
28
    protected $page;
29
30
    /**
31
     *
32
     * @var string
33
     */
34
    protected $order;
35
36
    /**
37
     *
38
     * @var string
39
     */
40
    protected $column;
41
42
    /**
43
     *
44
     * @var int
45
     */
46
    protected $itemCountPerPage;
47
48
    /**
49
     * Quick search
50
     * @var string
51
     */
52
    protected $quickSearch;
53
54
55
     /**
56
     * Array of filters
57
     * @var array
58
     */
59
    protected $filters;
60
61
    const DEFAULT_PAGE = 1;
62
    const DEFAULT_ORDER = 'asc';
63
    const DEFAULT_ITEM_COUNT_PER_PAGE = 2;
64
65
66 View Code Duplication
    public function __construct($object)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
67
    {
68
        if ($object instanceof \ArrayObject) {
69
            $this->object = $object;
70
        } elseif ($object instanceof \Zend\Stdlib\ArrayObject) {
0 ignored issues
show
Bug introduced by
The class Zend\Stdlib\ArrayObject does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
71
            $this->object = $object;
0 ignored issues
show
Documentation Bug introduced by
It seems like $object of type object<Zend\Stdlib\ArrayObject> is incompatible with the declared type object<ArrayObject> of property $object.

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...
72
        } else {
73
            throw new Exception\InvalidArgumentException('parameter must be instance of ArrayObject');
74
        }
75
    }
76
77
    /**
78
     * Init method
79
     */
80
    public function init()
81
    {
82
        $array = (method_exists($this->object, 'toArray')) ? $this->object->toArray() : $this->object->getArrayCopy();
83
84
        $this->page = (isset($array['zfTablePage'])) ? $array['zfTablePage'] : self::DEFAULT_PAGE;
85
        $this->column = (isset($array['zfTableColumn'])) ? $array['zfTableColumn'] : null;
86
        $this->order = (isset($array['zfTableOrder'])) ? $array['zfTableOrder'] : self::DEFAULT_ORDER;
87
        $this->itemCountPerPage = (isset($array['zfTableItemPerPage']))
88
            ? $array['zfTableItemPerPage'] : $this->getOptions()->getItemCountPerPage();
89
        $this->quickSearch = (isset($array['zfTableQuickSearch'])) ? $array['zfTableQuickSearch'] : '';
90
91
        //Init filters value
92
        if ($this->getTable()->getOptions('showColumnFilters')) {
0 ignored issues
show
Unused Code introduced by
The call to AbstractTable::getOptions() has too many arguments starting with 'showColumnFilters'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
93
            foreach ($array as $key => $value) {
94
                if (substr($key, 0, 4) == 'zff_') {
95
                    $this->filters[$key] = $value;
96
                }
97
            }
98
        }
99
    }
100
101
    public function getPureValueOfFilter($key)
102
    {
103
        return $this->object[$key];
104
    }
105
106
    public function getValueOfFilter($key, $prefix = 'zff_')
107
    {
108
        return $this->filters[$prefix . $key];
109
    }
110
111
    /**
112
     * Get page
113
     *
114
     * @return int
115
     */
116
    public function getPage()
117
    {
118
        return $this->page;
119
    }
120
121
    /**
122
     * Set page
123
     *
124
     * @param string $page
125
     * @return $this
126
     */
127
    public function setPage($page)
128
    {
129
        $this->page = $page;
0 ignored issues
show
Documentation Bug introduced by
The property $page was declared of type integer, but $page is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
130
        return $this;
131
    }
132
133
    /**
134
     * Get order
135
     *
136
     * @return string
137
     */
138
    public function getOrder()
139
    {
140
        return $this->order;
141
    }
142
143
    /**
144
     * Set asc or desc ordering
145
     *
146
     * @param $order
147
     */
148
    public function setOrder($order)
149
    {
150
        $this->order = $order;
151
    }
152
153
    /**
154
     * Get column
155
     *
156
     * @return string
157
     */
158
    public function getColumn()
159
    {
160
        return ($this->column == '') ? null : $this->column;
161
    }
162
163
    /**
164
     *
165
     * @param string $column
166
     * @return $this
167
     */
168
    public function setColumn($column)
169
    {
170
        $this->column = $column;
171
        return $this;
172
    }
173
174
    /**
175
     * Get item count per page
176
     *
177
     * @return int
178
     */
179
    public function getItemCountPerPage()
180
    {
181
        return $this->itemCountPerPage;
182
    }
183
184
    /**
185
     *
186
     * @param int $itemCountPerPage
187
     */
188
    public function setItemCountPerPage($itemCountPerPage)
189
    {
190
        $this->itemCountPerPage = $itemCountPerPage;
191
    }
192
193
    /**
194
     * Return offset
195
     *
196
     * @return int
197
     */
198
    public function getOffset()
199
    {
200
        return ($this->getPage() * $this->getItemCountPerPage()) - $this->getItemCountPerPage();
201
    }
202
203
    /**
204
     * Get quick search string
205
     *
206
     * @return string
207
     */
208
    public function getQuickSearch()
209
    {
210
        return $this->quickSearch;
211
    }
212
}
213