Issues (150)

src/Helpers/SqlOptions.php (1 issue)

1
<?php
2
3
namespace SoliDry\Helpers;
4
5
use SoliDry\Extension\BaseFormRequest;
6
use SoliDry\Types\ModelsInterface;
7
8
/**
9
 * Class SqlOptions
10
 * @package SoliDry\Helpers
11
 *
12
 * @property BaseFormRequest formRequest
13
 */
14
class SqlOptions
15
{
16
    /**
17
     * @var int
18
     */
19
    public int $id      = 0;
20
21
    /**
22
     * @var int
23
     */
24
    public int $limit   = ModelsInterface::DEFAULT_LIMIT;
25
26
    /**
27
     * @var int
28
     */
29
    public int $page    = ModelsInterface::DEFAULT_PAGE;
30
31
    /**
32
     * @var array
33
     */
34
    public array $orderBy = [];
35
36
    /**
37
     * @var array|string[]
38
     */
39
    public array $data    = ModelsInterface::DEFAULT_DATA;
40
41
    /**
42
     * @var array
43
     */
44
    public array $filter  = [];
45
46
    public $formRequest;
47
48
    /**
49
     * @return int
50
     */
51
    public function getLimit() : int
52
    {
53
        return $this->limit;
54
    }
55
56
    /**
57
     * @param int $limit
58
     */
59
    public function setLimit($limit) : void
60
    {
61
        $this->limit = $limit;
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    public function getPage() : int
68
    {
69
        return $this->page;
70
    }
71
72
    /**
73
     * @param int $page
74
     */
75
    public function setPage(int $page) : void
76
    {
77
        $this->page = $page;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getOrderBy() : array
84
    {
85
        return $this->orderBy;
86
    }
87
88
    /**
89
     * @param array $orderBy
90
     */
91
    public function setOrderBy($orderBy) : void
92
    {
93
        $this->orderBy = $orderBy;
94
    }
95
96
    /**
97
     * @return array
98
     */
99
    public function getData() : array
100
    {
101
        return $this->data;
102
    }
103
104
    /**
105
     * @param array $data
106
     */
107
    public function setData($data) : void
108
    {
109
        // id must be there anyway
110
        $this->data = $data;
111
        if(\in_array(ModelsInterface::ID, $this->data, true) === false)
112
        {
113
            $this->data[] = ModelsInterface::ID;
114
        }
115
116
        // this fix cases where oneToMany/oneToOne relationships need binding by entity_id
117
        $rules = $this->formRequest->rules();
118
        foreach ($rules as $key => $val) {
119
120
            if (mb_strpos($key, '_id') !== false) {
121
                if (\in_array($key, $this->data, true) === false) {
122
                    $this->data[] = $key;
123
                }
124
            }
125
        }
126
    }
127
128
    /**
129
     * @return array
130
     */
131
    public function getFilter() : array
132
    {
133
        return $this->filter;
134
    }
135
136
    /**
137
     * @param array $filter
138
     */
139
    public function setFilter($filter) : void
140
    {
141
        $this->filter = $filter;
142
    }
143
144
    /**
145
     * @return int|string
146
     */
147
    public function getId()
148
    {
149
        return $this->id;
150
    }
151
152
    /**
153
     * @param int|string $id
154
     */
155
    public function setId($id) : void
156
    {
157
        $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $id can also be of type string. However, the property $id 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...
158
    }
159
160
    /**
161
     * @param BaseFormRequest $formRequest
162
     */
163
    public function setFormRequest(BaseFormRequest $formRequest): void
164
    {
165
        $this->formRequest = $formRequest;
166
    }
167
}