Skip to content

Commit 9dab5f1

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents fff435c + 1d6b7ac commit 9dab5f1

File tree

13 files changed

+80
-132
lines changed

13 files changed

+80
-132
lines changed

rector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
4646
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
4747
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
48-
use Utils\Rector\RemoveVarTagFromClassConstantRector;
4948
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
5049

5150
return static function (RectorConfig $rectorConfig): void {
@@ -135,7 +134,6 @@
135134
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
136135
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
137136
$rectorConfig->rule(RemoveErrorSuppressInTryCatchStmtsRector::class);
138-
$rectorConfig->rule(RemoveVarTagFromClassConstantRector::class);
139137
$rectorConfig->rule(SimplifyRegexPatternRector::class);
140138
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
141139
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);

system/BaseModel.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
* - ensure validation is run against objects when saving items
4242
* - process various callbacks
4343
* - allow intermingling calls to the db connection
44+
*
45+
* @phpstan-type row_array array<int|string, float|int|null|string>
46+
* @phpstan-type event_data_beforeinsert array{data: row_array}
47+
* @phpstan-type event_data_afterinsert array{id: int|string, data: row_array, result: bool}
48+
* @phpstan-type event_data_beforefind array{id?: int|string, method: string, singleton: bool, limit?: int, offset?: int}
49+
* @phpstan-type event_data_afterfind array{id: int|string|null|list<int|string>, data: row_array|list<row_array>|object|null, method: string, singleton: bool}
50+
* @phpstan-type event_data_beforeupdate array{id: null|list<int|string>, data: row_array}
51+
* @phpstan-type event_data_afterupdate array{id: null|list<int|string>, data: row_array|object, result: bool}
52+
* @phpstan-type event_data_beforedelete array{id: null|list<int|string>, purge: bool}
53+
* @phpstan-type event_data_afterdelete array{id: null|list<int|string>, data: null, purge: bool, result: bool}
4454
*/
4555
abstract class BaseModel
4656
{
@@ -519,6 +529,7 @@ abstract public function chunk(int $size, Closure $userFunc);
519529
* @param array|int|string|null $id One primary key or an array of primary keys
520530
*
521531
* @return array|object|null The resulting row of data, or null.
532+
* @phpstan-return ($id is int|string ? row_array|object|null : list<row_array|object>)
522533
*/
523534
public function find($id = null)
524535
{

system/Database/BaseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,9 +2738,9 @@ public function getCompiledDelete(bool $reset = true): string
27382738
/**
27392739
* Compiles a delete string and runs the query
27402740
*
2741-
* @param mixed $where
2741+
* @param array|RawSql|string $where
27422742
*
2743-
* @return bool|string Returns a string if in test mode.
2743+
* @return bool|string Returns a SQL string if in test mode.
27442744
*
27452745
* @throws DatabaseException
27462746
*/

system/Database/MigrationRunner.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,11 @@ class MigrationRunner
122122
protected $groupSkip = false;
123123

124124
/**
125-
* Constructor.
125+
* The migration can manage multiple databases. So it should always use the
126+
* default DB group so that it creates the `migrations` table in the default
127+
* DB group. Therefore, passing $db is for testing purposes only.
126128
*
127-
* When passing in $db, you may pass any of the following to connect:
128-
* - group name
129-
* - existing connection instance
130-
* - array of database configuration values
131-
*
132-
* @param array|ConnectionInterface|string|null $db
129+
* @param array|ConnectionInterface|string|null $db DB group. For testing purposes only.
133130
*
134131
* @throws ConfigException
135132
*/

system/HTTP/RequestTrait.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ trait RequestTrait
3535
protected $ipAddress = '';
3636

3737
/**
38-
* Stores values we've retrieved from
39-
* PHP globals.
38+
* Stores values we've retrieved from PHP globals.
4039
*
41-
* @var array
40+
* @var array{get?: array, post?: array, request?: array, cookie?: array, server?: array}
4241
*/
4342
protected $globals = [];
4443

@@ -204,22 +203,27 @@ public function getServer($index = null, $filter = null, $flags = null)
204203
* @param array|int|null $flags
205204
*
206205
* @return mixed
206+
*
207+
* @deprecated 4.4.4 This method does not work from the beginning. Use `env()`.
207208
*/
208209
public function getEnv($index = null, $filter = null, $flags = null)
209210
{
211+
// @phpstan-ignore-next-line
210212
return $this->fetchGlobal('env', $index, $filter, $flags);
211213
}
212214

213215
/**
214216
* Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
215217
*
218+
* @param string $name Supergrlobal name (lowercase)
219+
* @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
216220
* @param mixed $value
217221
*
218222
* @return $this
219223
*/
220-
public function setGlobal(string $method, $value)
224+
public function setGlobal(string $name, $value)
221225
{
222-
$this->globals[$method] = $value;
226+
$this->globals[$name] = $value;
223227

224228
return $this;
225229
}
@@ -234,19 +238,18 @@ public function setGlobal(string $method, $value)
234238
*
235239
* http://php.net/manual/en/filter.filters.sanitize.php
236240
*
237-
* @param string $method Input filter constant
241+
* @param string $name Supergrlobal name (lowercase)
242+
* @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
238243
* @param array|string|null $index
239244
* @param int|null $filter Filter constant
240245
* @param array|int|null $flags Options
241246
*
242247
* @return array|bool|float|int|object|string|null
243248
*/
244-
public function fetchGlobal(string $method, $index = null, ?int $filter = null, $flags = null)
249+
public function fetchGlobal(string $name, $index = null, ?int $filter = null, $flags = null)
245250
{
246-
$method = strtolower($method);
247-
248-
if (! isset($this->globals[$method])) {
249-
$this->populateGlobals($method);
251+
if (! isset($this->globals[$name])) {
252+
$this->populateGlobals($name);
250253
}
251254

252255
// Null filters cause null values to return.
@@ -257,9 +260,9 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
257260
if ($index === null) {
258261
$values = [];
259262

260-
foreach ($this->globals[$method] as $key => $value) {
263+
foreach ($this->globals[$name] as $key => $value) {
261264
$values[$key] = is_array($value)
262-
? $this->fetchGlobal($method, $key, $filter, $flags)
265+
? $this->fetchGlobal($name, $key, $filter, $flags)
263266
: filter_var($value, $filter, $flags);
264267
}
265268

@@ -271,15 +274,15 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
271274
$output = [];
272275

273276
foreach ($index as $key) {
274-
$output[$key] = $this->fetchGlobal($method, $key, $filter, $flags);
277+
$output[$key] = $this->fetchGlobal($name, $key, $filter, $flags);
275278
}
276279

277280
return $output;
278281
}
279282

280283
// Does the index contain array notation?
281284
if (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) {
282-
$value = $this->globals[$method];
285+
$value = $this->globals[$name];
283286

284287
for ($i = 0; $i < $count; $i++) {
285288
$key = trim($matches[0][$i], '[]');
@@ -297,7 +300,7 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
297300
}
298301

299302
if (! isset($value)) {
300-
$value = $this->globals[$method][$index] ?? null;
303+
$value = $this->globals[$name][$index] ?? null;
301304
}
302305

303306
if (is_array($value)
@@ -326,20 +329,23 @@ public function fetchGlobal(string $method, $index = null, ?int $filter = null,
326329
}
327330

328331
/**
329-
* Saves a copy of the current state of one of several PHP globals
332+
* Saves a copy of the current state of one of several PHP globals,
330333
* so we can retrieve them later.
331334
*
335+
* @param string $name Superglobal name (lowercase)
336+
* @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name
337+
*
332338
* @return void
333339
*/
334-
protected function populateGlobals(string $method)
340+
protected function populateGlobals(string $name)
335341
{
336-
if (! isset($this->globals[$method])) {
337-
$this->globals[$method] = [];
342+
if (! isset($this->globals[$name])) {
343+
$this->globals[$name] = [];
338344
}
339345

340346
// Don't populate ENV as it might contain
341347
// sensitive data that we don't want to get logged.
342-
switch ($method) {
348+
switch ($name) {
343349
case 'get':
344350
$this->globals['get'] = $_GET;
345351
break;

system/Model.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
* @method $this where($key, $value = null, ?bool $escape = null)
8282
* @method $this whereIn(?string $key = null, $values = null, ?bool $escape = null)
8383
* @method $this whereNotIn(?string $key = null, $values = null, ?bool $escape = null)
84+
*
85+
* @phpstan-import-type row_array from BaseModel
8486
*/
8587
class Model extends BaseModel
8688
{
@@ -175,6 +177,7 @@ public function setTable(string $table)
175177
* @param array|int|string|null $id One primary key or an array of primary keys
176178
*
177179
* @return array|object|null The resulting row of data, or null.
180+
* @phpstan-return ($singleton is true ? row_array|null|object : list<row_array|object>)
178181
*/
179182
protected function doFind(bool $singleton, $id = null)
180183
{
@@ -221,6 +224,7 @@ protected function doFindColumn(string $columnName)
221224
* @param int $offset Offset
222225
*
223226
* @return array
227+
* @phpstan-return list<row_array|object>
224228
*/
225229
protected function doFindAll(int $limit = 0, int $offset = 0)
226230
{
@@ -241,6 +245,7 @@ protected function doFindAll(int $limit = 0, int $offset = 0)
241245
* This method works only with dbCalls.
242246
*
243247
* @return array|object|null
248+
* @phpstan-return row_array|object|null
244249
*/
245250
protected function doFirst()
246251
{
@@ -408,7 +413,7 @@ protected function doUpdateBatch(?array $set = null, ?string $index = null, int
408413
* @param array|int|string|null $id The rows primary key(s)
409414
* @param bool $purge Allows overriding the soft deletes setting.
410415
*
411-
* @return bool|string
416+
* @return bool|string SQL string when testMode
412417
*
413418
* @throws DatabaseException
414419
*/
@@ -447,7 +452,7 @@ protected function doDelete($id = null, bool $purge = false)
447452
* through soft deletes (deleted = 1)
448453
* This method works only with dbCalls.
449454
*
450-
* @return bool|string Returns a string if in test mode.
455+
* @return bool|string Returns a SQL string if in test mode.
451456
*/
452457
protected function doPurgeDeleted()
453458
{
@@ -488,7 +493,7 @@ protected function doReplace(?array $data = null, bool $returnSQL = false)
488493
* ['source' => 'message']
489494
* This method works only with dbCalls.
490495
*
491-
* @return array<string,string>
496+
* @return array<string, string>
492497
*/
493498
protected function doErrors()
494499
{

user_guide_src/source/changelogs/v4.4.4.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Changes
4141
Deprecations
4242
************
4343

44+
- **Request:** The :php:meth:`CodeIgniter\\HTTP\\Request::getEnv()` method is
45+
deprecated. This method does not work from the beginning. Use :php:func:`env()`
46+
instead.
47+
4448
**********
4549
Bugs Fixed
4650
**********

user_guide_src/source/dbmgmt/migration.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Database Groups
6666
===============
6767

6868
A migration will only be run against a single database group. If you have multiple groups defined in
69-
**app/Config/Database.php**, then it will run against the ``$defaultGroup`` as specified
69+
**app/Config/Database.php**, then by default it will run against the ``$defaultGroup`` as specified
7070
in that same configuration file.
7171

7272
There may be times when you need different schemas for different
@@ -79,6 +79,9 @@ match the name of the database group exactly:
7979

8080
.. literalinclude:: migration/003.php
8181

82+
.. note:: The **migrations** table that tracks which migrations have already been
83+
run will be always created in the default database group.
84+
8285
Namespaces
8386
==========
8487

0 commit comments

Comments
 (0)