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.

AdapterDataTables::setColumn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 AdapterDataTables 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
    const DEFAULT_PAGE = 1;
55
    const DEFAULT_ORDER = 'asc';
56
    const DEFAULT_ITEM_COUNT_PER_PAGE = 2;
57
58 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...
59
    {
60
        if ($object instanceof \ArrayObject) {
61
            $this->object = $object;
62
        } 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...
63
            $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...
64
        } else {
65
            throw new Exception\InvalidArgumentException('parameter must be instance of ArrayObject');
66
        }
67
    }
68
69
    /**
70
     * Init method
71
     */
72
    public function init()
73
    {
74
        $array = $this->object->toArray();
75
        $this->page = (isset($array['iDisplayStart']))
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($array['iDisplaySt... 1 : self::DEFAULT_PAGE can also be of type double. However, the property $page is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
76
            ? ($array['iDisplayStart'] / $array['iDisplayLength'] + 1) : self::DEFAULT_PAGE;
77
78
        if (isset($array['iSortCol_0'])) {
79
            $headers = $this->getTable()->getHeaders();
80
            $slice = array_slice($headers, $array['iSortCol_0'], 1);
81
            $this->column = key($slice);
82
        }
83
84
        $this->order = (isset($array['sSortDir_0'])) ? $array['sSortDir_0'] : self::DEFAULT_ORDER;
85
        $this->itemCountPerPage = (isset($array['iDisplayLength'])) ? $array['iDisplayLength'] : 999;
86
        $this->quickSearch = (isset($array['sSearch'])) ? $array['sSearch'] : '';
87
    }
88
89
    /**
90
     * Get page
91
     *
92
     * @return int
93
     */
94
    public function getPage()
95
    {
96
        return $this->page;
97
    }
98
99
    /**
100
     * Set page
101
     *
102
     * @param int $page
103
     * @return $this
104
     */
105
    public function setPage($page)
106
    {
107
        $this->page = $page;
108
        return $this;
109
    }
110
111
    /**
112
     * Get order
113
     *
114
     * @return string
115
     */
116
    public function getOrder()
117
    {
118
        return $this->order;
119
    }
120
121
    /**
122
     * Set asc or desc ordering
123
     *
124
     * @param string $order
125
     */
126
    public function setOrder($order)
127
    {
128
        $this->order = $order;
129
    }
130
131
    /**
132
     * Get column
133
     *
134
     * @return string
135
     */
136
    public function getColumn()
137
    {
138
        return ($this->column == '') ? null : $this->column;
139
    }
140
141
    /**
142
     *
143
     * @param string $column
144
     * @return $this
145
     */
146
    public function setColumn($column)
147
    {
148
        $this->column = $column;
149
        return $this;
150
    }
151
152
    /**
153
     * Get item count per page
154
     *
155
     * @return int
156
     */
157
    public function getItemCountPerPage()
158
    {
159
        return $this->itemCountPerPage;
160
    }
161
162
    /**
163
     *
164
     * @param int $itemCountPerPage
165
     */
166
    public function setItemCountPerPage($itemCountPerPage)
167
    {
168
        $this->itemCountPerPage = $itemCountPerPage;
169
    }
170
171
    /**
172
     * Return offset
173
     *
174
     * @return int
175
     */
176
    public function getOffset()
177
    {
178
        return ($this->getPage() * $this->getItemCountPerPage()) - $this->getItemCountPerPage();
179
    }
180
181
    /**
182
     * Get quick search string
183
     *
184
     * @return string
185
     */
186
    public function getQuickSearch()
187
    {
188
        return $this->quickSearch;
189
    }
190
}
191