Skip to content

Commit c3bfac5

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.6
# Conflicts: # composer.json # utils/phpstan-baseline/missingType.iterableValue.neon
2 parents cc96fe3 + 61741c5 commit c3bfac5

30 files changed

+131
-114
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"phpunit/phpcov": "^9.0.2 || ^10.0",
2929
"phpunit/phpunit": "^10.5.16 || ^11.2",
3030
"predis/predis": "^1.1 || ^2.3",
31-
"rector/rector": "2.0.4",
31+
"rector/rector": "2.0.5",
3232
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
3333
},
3434
"replace": {

system/CLI/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public static function promptByKey($text, array $options, $validation = null): s
289289

290290
CLI::isZeroOptions($options);
291291

292-
if ($line = array_shift($text)) {
292+
if (($line = array_shift($text)) !== null) {
293293
CLI::write($line);
294294
}
295295

@@ -348,7 +348,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
348348
// return the prompt again if $input contain(s) non-numeric character, except a comma.
349349
// And if max from $options less than max from input,
350350
// it means user tried to access null value in $options
351-
if ($pattern === 0 || $maxOptions < $maxInput) {
351+
if ($pattern < 1 || $maxOptions < $maxInput) {
352352
static::error('Please select correctly.');
353353
CLI::newLine();
354354

system/Database/BaseBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ public function join(string $table, $cond, string $type = '', ?bool $escape = nu
668668
} else {
669669
// Split multiple conditions
670670
// @TODO This does not parse `BETWEEN a AND b` correctly.
671-
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
671+
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE) >= 1) {
672672
$conditions = [];
673673
$joints = $joints[0];
674674
array_unshift($joints, ['', 0]);
@@ -2203,7 +2203,7 @@ protected function formatValues(array $values): array
22032203
*
22042204
* @param array|object|null $set a dataset
22052205
*
2206-
* @return false|int|list<string> Number of rows inserted or FALSE on failure, SQL array when testMode
2206+
* @return false|int|list<string> Number of rows inserted or FALSE on no data to perform an insert operation, SQL array when testMode
22072207
*/
22082208
public function insertBatch($set = null, ?bool $escape = null, int $batchSize = 100)
22092209
{
@@ -3477,7 +3477,7 @@ protected function getOperator(string $str, bool $list = false)
34773477
'/' . implode('|', $this->pregOperators) . '/i',
34783478
$str,
34793479
$match
3480-
) ? ($list ? $match[0] : $match[0][0]) : false;
3480+
) >= 1 ? ($list ? $match[0] : $match[0][0]) : false;
34813481
}
34823482

34833483
/**
@@ -3508,7 +3508,7 @@ private function getOperatorFromWhereKey(string $whereKey)
35083508
'/' . implode('|', $pregOperators) . '/i',
35093509
$whereKey,
35103510
$match
3511-
) ? $match[0] : false;
3511+
) >= 1 ? $match[0] : false;
35123512
}
35133513

35143514
/**

system/Database/Postgre/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ protected function getDriverFunctionPrefix(): string
228228
*/
229229
public function affectedRows(): int
230230
{
231+
if ($this->resultID === false) {
232+
return 0;
233+
}
234+
231235
return pg_affected_rows($this->resultID);
232236
}
233237

system/Database/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ protected function matchNamedBinds(string $sql, array $binds): string
342342
*/
343343
protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml): string
344344
{
345-
if ($c = preg_match_all("/'[^']*'/", $sql, $matches)) {
345+
if ($c = preg_match_all("/'[^']*'/", $sql, $matches) >= 1) {
346346
$c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', str_replace($matches[0], str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]), $sql, $c), $matches, PREG_OFFSET_CAPTURE);
347347

348348
// Bind values' count must match the count of markers in the query

system/Database/SQLSRV/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function join(string $table, $cond, string $type = '', ?bool $escape = nu
122122
$cond = ' ON ' . $cond;
123123
} else {
124124
// Split multiple conditions
125-
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
125+
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE) >= 1) {
126126
$conditions = [];
127127
$joints = $joints[0];
128128
array_unshift($joints, ['', 0]);

system/Database/SQLSRV/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ public function error(): array
453453
*/
454454
public function affectedRows(): int
455455
{
456+
if ($this->resultID === false) {
457+
return 0;
458+
}
459+
456460
return sqlsrv_rows_affected($this->resultID);
457461
}
458462

system/Email/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ public function wordWrap($str, $charlim = null)
10311031

10321032
$unwrap = [];
10331033

1034-
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
1034+
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches) >= 1) {
10351035
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
10361036
$unwrap[] = $matches[1][$i];
10371037
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);

system/Helpers/text_helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function ascii_to_entities(string $str): string
132132
*/
133133
function entities_to_ascii(string $str, bool $all = true): string
134134
{
135-
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
135+
if (preg_match_all('/\&#(\d+)\;/', $str, $matches) >= 1) {
136136
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
137137
$digits = (int) $matches[1][$i];
138138
$out = '';
@@ -196,7 +196,7 @@ function word_censor(string $str, array $censored, string $replacement = ''): st
196196
"\\1{$replacement}\\3",
197197
$str
198198
);
199-
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
199+
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) >= 1) {
200200
$matches = $matches[1];
201201

202202
for ($i = count($matches) - 1; $i >= 0; $i--) {
@@ -352,7 +352,7 @@ function word_wrap(string $str, int $charlim = 76): string
352352
// strip the entire chunk and replace it with a marker.
353353
$unwrap = [];
354354

355-
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
355+
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches) >= 1) {
356356
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
357357
$unwrap[] = $matches[1][$i];
358358
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);

system/Helpers/url_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ function auto_link(string $str, string $type = 'both', bool $popup = false): str
360360
$str,
361361
$matches,
362362
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
363-
)
363+
) >= 1
364364
) {
365365
// Set our target HTML if using popup links.
366366
$target = ($popup) ? ' target="_blank"' : '';
@@ -387,7 +387,7 @@ function auto_link(string $str, string $type = 'both', bool $popup = false): str
387387
$str,
388388
$matches,
389389
PREG_OFFSET_CAPTURE
390-
)
390+
) >= 1
391391
) {
392392
foreach (array_reverse($matches[0]) as $match) {
393393
if (filter_var($match[0], FILTER_VALIDATE_EMAIL) !== false) {

system/Images/Handlers/BaseHandler.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -396,23 +396,6 @@ public function flip(string $dir = 'vertical')
396396
*/
397397
abstract protected function _flip(string $direction);
398398

399-
/**
400-
* Overlays a string of text over the image.
401-
*
402-
* Valid options:
403-
*
404-
* - color Text Color (hex number)
405-
* - shadowColor Color of the shadow (hex number)
406-
* - hAlign Horizontal alignment: left, center, right
407-
* - vAlign Vertical alignment: top, middle, bottom
408-
* - hOffset
409-
* - vOffset
410-
* - fontPath
411-
* - fontSize
412-
* - shadowOffset
413-
*
414-
* @return $this
415-
*/
416399
public function text(string $text, array $options = [])
417400
{
418401
$options = array_merge($this->textDefaults, $options);
@@ -427,6 +410,21 @@ public function text(string $text, array $options = [])
427410
/**
428411
* Handler-specific method for overlaying text on an image.
429412
*
413+
* @param array{
414+
* color?: string,
415+
* shadowColor?: string,
416+
* hAlign?: string,
417+
* vAlign?: string,
418+
* hOffset?: int,
419+
* vOffset?: int,
420+
* fontPath?: string,
421+
* fontSize?: int,
422+
* shadowOffset?: int,
423+
* opacity?: float,
424+
* padding?: int,
425+
* withShadow?: bool|string
426+
* } $options
427+
*
430428
* @return void
431429
*/
432430
abstract protected function _text(string $text, array $options = []);

system/Images/Handlers/ImageMagickHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@ protected function supportedFormatCheck()
329329
/**
330330
* Handler-specific method for overlaying text on an image.
331331
*
332-
* @return void
333-
*
334332
* @throws Exception
335333
*/
336334
protected function _text(string $text, array $options = [])

system/Images/ImageHandlerInterface.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,21 @@ public function fit(int $width, int $height, string $position);
117117
* - shadowColor Color of the shadow (hex number)
118118
* - hAlign Horizontal alignment: left, center, right
119119
* - vAlign Vertical alignment: top, middle, bottom
120-
* - hOffset
121-
* - vOffset
122-
* - fontPath
123-
* - fontSize
124-
* - shadowOffset
120+
*
121+
* @param array{
122+
* color?: string,
123+
* shadowColor?: string,
124+
* hAlign?: string,
125+
* vAlign?: string,
126+
* hOffset?: int,
127+
* vOffset?: int,
128+
* fontPath?: string,
129+
* fontSize?: int,
130+
* shadowOffset?: int,
131+
* opacity?: float,
132+
* padding?: int,
133+
* withShadow?: bool|string
134+
* } $options
125135
*
126136
* @return $this
127137
*/

system/Session/Handlers/MemcachedHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function open($path, $name): bool
9898
$this->savePath,
9999
$matches,
100100
PREG_SET_ORDER
101-
) === 0
101+
) < 1
102102
) {
103103
$this->memcached = null;
104104
$this->logger->error('Session: Invalid Memcached save path format: ' . $this->savePath);

system/Test/Mock/MockCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MockCache extends BaseHandler implements CacheInterface
3131
/**
3232
* Expiration times.
3333
*
34-
* @var ?list<int>
34+
* @var array<string, int|null>
3535
*/
3636
protected $expirations = [];
3737

system/Typography/Typography.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
9696

9797
// HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed
9898
$htmlComments = [];
99-
if (str_contains($str, '<!--') && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches)) {
99+
if (str_contains($str, '<!--') && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches) >= 1) {
100100
for ($i = 0, $total = count($matches[0]); $i < $total; $i++) {
101101
$htmlComments[] = $matches[0][$i];
102102
$str = str_replace($matches[0][$i], '{@HC' . $i . '}', $str);

system/View/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ protected function extractNoparse(string $template): string
419419
* $matches[][0] is the raw match
420420
* $matches[][1] is the contents
421421
*/
422-
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER)) {
422+
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) >= 1) {
423423
foreach ($matches as $match) {
424424
// Create a hash of the contents to insert in its place.
425425
$hash = md5($match[1]);
@@ -691,7 +691,7 @@ protected function parsePlugins(string $template)
691691
* $matches[1] = all parameters string in opening tag
692692
* $matches[2] = content between the tags to send to the plugin.
693693
*/
694-
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) === 0) {
694+
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) < 1) {
695695
continue;
696696
}
697697

tests/system/CommonHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function foo_bar_baz(): string
148148
}
149149
}
150150

151-
$this->assertSame($this->dummyHelpers[0], foo_bar_baz());
151+
$this->assertSame($this->dummyHelpers[0], foo_bar_baz()); // @phpstan-ignore-line function.notFound
152152
}
153153

154154
public function testNamespacedHelperNotFound(): void

tests/system/Database/Builder/SelectTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use CodeIgniter\Database\SQLSRV\Builder as SQLSRVBuilder;
2020
use CodeIgniter\Test\CIUnitTestCase;
2121
use CodeIgniter\Test\Mock\MockConnection;
22+
use Generator;
2223
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\Attributes\Group;
2425

@@ -82,7 +83,7 @@ public function testSelectAcceptsArrayWithRawSql(array $select, string $expected
8283
}
8384

8485
/**
85-
* @return list<list<RawSql|string>|string>
86+
* @return Generator<list<RawSql|string>|string>
8687
*/
8788
public static function provideSelectAcceptsArrayWithRawSql(): iterable
8889
{

tests/system/Database/Live/InsertTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CodeIgniter\Database\Live;
1515

16+
use CodeIgniter\Database\Exceptions\DatabaseException;
1617
use CodeIgniter\Database\Forge;
1718
use CodeIgniter\Database\RawSql;
1819
use CodeIgniter\Test\CIUnitTestCase;
@@ -79,13 +80,41 @@ public function testInsertBatch(): void
7980
],
8081
];
8182

82-
$this->db->table($table)->insertBatch($data);
83+
$count = $this->db->table($table)->insertBatch($data);
84+
85+
$this->assertSame(2, $count);
8386

8487
$expected = $data;
8588
$this->seeInDatabase($table, $expected[0]);
8689
$this->seeInDatabase($table, $expected[1]);
8790
}
8891

92+
public function testInsertBatchFailed(): void
93+
{
94+
$this->expectException(DatabaseException::class);
95+
96+
$data = [
97+
[
98+
'name' => 'Grocery Sales',
99+
],
100+
[
101+
'name' => null,
102+
],
103+
];
104+
105+
$db = $this->db;
106+
107+
if ($this->db->DBDriver === 'MySQLi') {
108+
// strict mode is required for MySQLi to throw an exception here
109+
$config = config('Database');
110+
$config->tests['strictOn'] = true;
111+
112+
$db = Database::connect($config->tests);
113+
}
114+
115+
$db->table('job')->insertBatch($data);
116+
}
117+
89118
public function testReplaceWithNoMatchingData(): void
90119
{
91120
$data = [

0 commit comments

Comments
 (0)