Completed
Push — master ( 7a35bc...7eff79 )
by Krzysztof
05:49 queued 02:58
created

PaginationCriteria::shouldBeApplied()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 2
eloc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace KGzocha\Searcher\Criteria;
4
5
/**
6
 * @author Krzysztof Gzocha <[email protected]>
7
 */
8
class PaginationCriteria implements PaginationCriteriaInterface
9
{
10
    /**
11
     * @var int
12
     */
13
    private $page;
14
15
    /**
16
     * @var int
17
     */
18
    private $itemsPerPage;
19
20
    /**
21
     * @param int $page
22
     * @param int $itemsPerPage
23
     */
24 17
    public function __construct(
25
        $page,
26
        $itemsPerPage
27
    ) {
28 17
        $this->page = $this->convert($page);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convert($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...
29 17
        $this->itemsPerPage = $this->convert($itemsPerPage);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convert($itemsPerPage) can also be of type double. However, the property $itemsPerPage 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...
30 17
    }
31
32
    /**
33
     * @return int
34
     */
35 6
    public function getPage()
36
    {
37 6
        return $this->page;
38
    }
39
40
    /**
41
     * @param int $page
42
     */
43 7
    public function setPage($page)
44
    {
45 7
        $this->page = $this->convert($page);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convert($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...
46 7
    }
47
48
    /**
49
     * @return int
50
     */
51 7
    public function getItemsPerPage()
52
    {
53 7
        return $this->itemsPerPage;
54
    }
55
56
    /**
57
     * @param int $itemsPerPage
58
     *
59
     * @throws \BadMethodCallException
60
     */
61 7
    public function setItemsPerPage($itemsPerPage)
62
    {
63 7
        $this->itemsPerPage = $this->convert($itemsPerPage);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convert($itemsPerPage) can also be of type double. However, the property $itemsPerPage 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...
64 7
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 8
    public function shouldBeApplied()
70
    {
71 8
        return $this->page != 0 && $this->itemsPerPage != 0;
72
    }
73
74
    /**
75
     * @param int $number
76
     *
77
     * @return int
78
     */
79 17
    private function convert($number)
80
    {
81 17
        return abs((int) $number);
82
    }
83
}
84