Merge remote-tracking branch 'upstream/develop' into 4.6

# Conflicts:
#	composer.json
#	utils/phpstan-baseline/missingType.iterableValue.neon
This commit is contained in:
michalsn 2025-01-06 09:51:34 +01:00
commit c3bfac5261
No known key found for this signature in database
GPG Key ID: 9ACAA935C3776CE9
30 changed files with 131 additions and 114 deletions

View File

@ -28,7 +28,7 @@
"phpunit/phpcov": "^9.0.2 || ^10.0",
"phpunit/phpunit": "^10.5.16 || ^11.2",
"predis/predis": "^1.1 || ^2.3",
"rector/rector": "2.0.4",
"rector/rector": "2.0.5",
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
},
"replace": {

View File

@ -289,7 +289,7 @@ class CLI
CLI::isZeroOptions($options);
if ($line = array_shift($text)) {
if (($line = array_shift($text)) !== null) {
CLI::write($line);
}
@ -348,7 +348,7 @@ class CLI
// return the prompt again if $input contain(s) non-numeric character, except a comma.
// And if max from $options less than max from input,
// it means user tried to access null value in $options
if ($pattern === 0 || $maxOptions < $maxInput) {
if ($pattern < 1 || $maxOptions < $maxInput) {
static::error('Please select correctly.');
CLI::newLine();

View File

@ -668,7 +668,7 @@ class BaseBuilder
} else {
// Split multiple conditions
// @TODO This does not parse `BETWEEN a AND b` correctly.
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE) >= 1) {
$conditions = [];
$joints = $joints[0];
array_unshift($joints, ['', 0]);
@ -2203,7 +2203,7 @@ class BaseBuilder
*
* @param array|object|null $set a dataset
*
* @return false|int|list<string> Number of rows inserted or FALSE on failure, SQL array when testMode
* @return false|int|list<string> Number of rows inserted or FALSE on no data to perform an insert operation, SQL array when testMode
*/
public function insertBatch($set = null, ?bool $escape = null, int $batchSize = 100)
{
@ -3477,7 +3477,7 @@ class BaseBuilder
'/' . implode('|', $this->pregOperators) . '/i',
$str,
$match
) ? ($list ? $match[0] : $match[0][0]) : false;
) >= 1 ? ($list ? $match[0] : $match[0][0]) : false;
}
/**
@ -3508,7 +3508,7 @@ class BaseBuilder
'/' . implode('|', $pregOperators) . '/i',
$whereKey,
$match
) ? $match[0] : false;
) >= 1 ? $match[0] : false;
}
/**

View File

@ -228,6 +228,10 @@ class Connection extends BaseConnection
*/
public function affectedRows(): int
{
if ($this->resultID === false) {
return 0;
}
return pg_affected_rows($this->resultID);
}

View File

@ -342,7 +342,7 @@ class Query implements QueryInterface, Stringable
*/
protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml): string
{
if ($c = preg_match_all("/'[^']*'/", $sql, $matches)) {
if ($c = preg_match_all("/'[^']*'/", $sql, $matches) >= 1) {
$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);
// Bind values' count must match the count of markers in the query

View File

@ -122,7 +122,7 @@ class Builder extends BaseBuilder
$cond = ' ON ' . $cond;
} else {
// Split multiple conditions
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE) >= 1) {
$conditions = [];
$joints = $joints[0];
array_unshift($joints, ['', 0]);

View File

@ -453,6 +453,10 @@ class Connection extends BaseConnection
*/
public function affectedRows(): int
{
if ($this->resultID === false) {
return 0;
}
return sqlsrv_rows_affected($this->resultID);
}

View File

@ -1031,7 +1031,7 @@ class Email
$unwrap = [];
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches) >= 1) {
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
$unwrap[] = $matches[1][$i];
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);

View File

@ -132,7 +132,7 @@ if (! function_exists('entities_to_ascii')) {
*/
function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
if (preg_match_all('/\&#(\d+)\;/', $str, $matches) >= 1) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = (int) $matches[1][$i];
$out = '';
@ -196,7 +196,7 @@ if (! function_exists('word_censor')) {
"\\1{$replacement}\\3",
$str
);
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) >= 1) {
$matches = $matches[1];
for ($i = count($matches) - 1; $i >= 0; $i--) {
@ -352,7 +352,7 @@ if (! function_exists('word_wrap')) {
// strip the entire chunk and replace it with a marker.
$unwrap = [];
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches) >= 1) {
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
$unwrap[] = $matches[1][$i];
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);

View File

@ -360,7 +360,7 @@ if (! function_exists('auto_link')) {
$str,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) >= 1
) {
// Set our target HTML if using popup links.
$target = ($popup) ? ' target="_blank"' : '';
@ -387,7 +387,7 @@ if (! function_exists('auto_link')) {
$str,
$matches,
PREG_OFFSET_CAPTURE
)
) >= 1
) {
foreach (array_reverse($matches[0]) as $match) {
if (filter_var($match[0], FILTER_VALIDATE_EMAIL) !== false) {

View File

@ -396,23 +396,6 @@ abstract class BaseHandler implements ImageHandlerInterface
*/
abstract protected function _flip(string $direction);
/**
* Overlays a string of text over the image.
*
* Valid options:
*
* - color Text Color (hex number)
* - shadowColor Color of the shadow (hex number)
* - hAlign Horizontal alignment: left, center, right
* - vAlign Vertical alignment: top, middle, bottom
* - hOffset
* - vOffset
* - fontPath
* - fontSize
* - shadowOffset
*
* @return $this
*/
public function text(string $text, array $options = [])
{
$options = array_merge($this->textDefaults, $options);
@ -427,6 +410,21 @@ abstract class BaseHandler implements ImageHandlerInterface
/**
* Handler-specific method for overlaying text on an image.
*
* @param array{
* color?: string,
* shadowColor?: string,
* hAlign?: string,
* vAlign?: string,
* hOffset?: int,
* vOffset?: int,
* fontPath?: string,
* fontSize?: int,
* shadowOffset?: int,
* opacity?: float,
* padding?: int,
* withShadow?: bool|string
* } $options
*
* @return void
*/
abstract protected function _text(string $text, array $options = []);

View File

@ -329,8 +329,6 @@ class ImageMagickHandler extends BaseHandler
/**
* Handler-specific method for overlaying text on an image.
*
* @return void
*
* @throws Exception
*/
protected function _text(string $text, array $options = [])

View File

@ -117,11 +117,21 @@ interface ImageHandlerInterface
* - shadowColor Color of the shadow (hex number)
* - hAlign Horizontal alignment: left, center, right
* - vAlign Vertical alignment: top, middle, bottom
* - hOffset
* - vOffset
* - fontPath
* - fontSize
* - shadowOffset
*
* @param array{
* color?: string,
* shadowColor?: string,
* hAlign?: string,
* vAlign?: string,
* hOffset?: int,
* vOffset?: int,
* fontPath?: string,
* fontSize?: int,
* shadowOffset?: int,
* opacity?: float,
* padding?: int,
* withShadow?: bool|string
* } $options
*
* @return $this
*/

View File

@ -98,7 +98,7 @@ class MemcachedHandler extends BaseHandler
$this->savePath,
$matches,
PREG_SET_ORDER
) === 0
) < 1
) {
$this->memcached = null;
$this->logger->error('Session: Invalid Memcached save path format: ' . $this->savePath);

View File

@ -31,7 +31,7 @@ class MockCache extends BaseHandler implements CacheInterface
/**
* Expiration times.
*
* @var ?list<int>
* @var array<string, int|null>
*/
protected $expirations = [];

View File

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

View File

@ -419,7 +419,7 @@ class Parser extends View
* $matches[][0] is the raw match
* $matches[][1] is the contents
*/
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER)) {
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) >= 1) {
foreach ($matches as $match) {
// Create a hash of the contents to insert in its place.
$hash = md5($match[1]);
@ -691,7 +691,7 @@ class Parser extends View
* $matches[1] = all parameters string in opening tag
* $matches[2] = content between the tags to send to the plugin.
*/
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) === 0) {
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) < 1) {
continue;
}

View File

@ -148,7 +148,7 @@ final class CommonHelperTest extends CIUnitTestCase
}
}
$this->assertSame($this->dummyHelpers[0], foo_bar_baz());
$this->assertSame($this->dummyHelpers[0], foo_bar_baz()); // @phpstan-ignore-line function.notFound
}
public function testNamespacedHelperNotFound(): void

View File

@ -19,6 +19,7 @@ use CodeIgniter\Database\RawSql;
use CodeIgniter\Database\SQLSRV\Builder as SQLSRVBuilder;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockConnection;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
@ -82,7 +83,7 @@ final class SelectTest extends CIUnitTestCase
}
/**
* @return list<list<RawSql|string>|string>
* @return Generator<list<RawSql|string>|string>
*/
public static function provideSelectAcceptsArrayWithRawSql(): iterable
{

View File

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace CodeIgniter\Database\Live;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Forge;
use CodeIgniter\Database\RawSql;
use CodeIgniter\Test\CIUnitTestCase;
@ -79,13 +80,41 @@ final class InsertTest extends CIUnitTestCase
],
];
$this->db->table($table)->insertBatch($data);
$count = $this->db->table($table)->insertBatch($data);
$this->assertSame(2, $count);
$expected = $data;
$this->seeInDatabase($table, $expected[0]);
$this->seeInDatabase($table, $expected[1]);
}
public function testInsertBatchFailed(): void
{
$this->expectException(DatabaseException::class);
$data = [
[
'name' => 'Grocery Sales',
],
[
'name' => null,
],
];
$db = $this->db;
if ($this->db->DBDriver === 'MySQLi') {
// strict mode is required for MySQLi to throw an exception here
$config = config('Database');
$config->tests['strictOn'] = true;
$db = Database::connect($config->tests);
}
$db->table('job')->insertBatch($data);
}
public function testReplaceWithNoMatchingData(): void
{
$data = [

View File

@ -239,4 +239,40 @@ final class TransactionTest extends CIUnitTestCase
$this->enableDBDebug();
}
/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/9362
*/
public function testTransInsertBatchFailed(): void
{
$data = [
[
'name' => 'Grocery Sales',
],
[
'name' => null,
],
];
$db = $this->db;
if ($this->db->DBDriver === 'MySQLi') {
// strict mode is required for MySQLi to throw an exception here
$config = config('Database');
$config->tests['strictOn'] = true;
$db = Database::connect($config->tests);
}
$db->transStrict(false)->transBegin();
$db->table('job')->insertBatch($data);
$this->assertFalse($db->transStatus());
$db->transComplete();
$db->transStrict();
$this->dontSeeInDatabase('job', ['name' => 'Grocery Sales']);
}
}

View File

@ -30,6 +30,8 @@ Deprecations
Bugs Fixed
**********
- **Database:** Fixed a bug where ``Builder::affectedRows()`` threw an error when the previous query call failed in ``Postgre`` and ``SQLSRV`` drivers.
See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.

View File

@ -1870,7 +1870,7 @@ Class Reference
:param array $set: Data to insert
:param bool $escape: Whether to escape values
:param int $batch_size: Count of rows to insert at once
:returns: Number of rows inserted or ``false`` on failure
:returns: Number of rows inserted or ``false`` on no data to perform an insert operation
:rtype: int|false
Compiles and executes batch ``INSERT`` statements.

View File

@ -1,8 +0,0 @@
# total 1 error
parameters:
ignoreErrors:
-
message: '#^Function foo_bar_baz not found\.$#'
count: 1
path: ../../tests/system/CommonHelperTest.php

View File

@ -1,8 +0,0 @@
# total 1 error
parameters:
ignoreErrors:
-
message: '#^Yield can be used only with these return types\: Generator, Iterator, Traversable, iterable\.$#'
count: 1
path: ../../tests/system/Database/Builder/SelectTest.php

View File

@ -1,8 +0,0 @@
# total 1 error
parameters:
ignoreErrors:
-
message: '#^Comparison operation "\>\=" between \(array\|float\|int\) and 0 results in an error\.$#'
count: 2
path: ../../system/Images/Handlers/ImageMagickHandler.php

View File

@ -1,8 +0,0 @@
# total 1 error
parameters:
ignoreErrors:
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
count: 1
path: ../../system/CLI/CLI.php

View File

@ -18,11 +18,7 @@ includes:
- expr.resultUnused.neon
- function.alreadyNarrowedType.neon
- function.inner.neon
- function.notFound.neon
- generator.returnType.neon
- generator.valueType.neon
- greaterOrEqual.invalid.neon
- if.condNotBoolean.neon
- isset.offset.neon
- isset.property.neon
- method.alreadyNarrowedType.neon
@ -55,6 +51,5 @@ includes:
- return.unusedType.neon
- staticMethod.notFound.neon
- ternary.shortNotAllowed.neon
- unset.offset.neon
- varTag.type.neon
- variable.undefined.neon

View File

@ -1,4 +1,4 @@
# total 1672 errors
# total 1667 errors
parameters:
ignoreErrors:
@ -4632,11 +4632,6 @@ parameters:
count: 1
path: ../../system/Images/Handlers/BaseHandler.php
-
message: '#^Method CodeIgniter\\Images\\Handlers\\BaseHandler\:\:_text\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Images/Handlers/BaseHandler.php
-
message: '#^Method CodeIgniter\\Images\\Handlers\\BaseHandler\:\:calcAspectRatio\(\) return type has no value type specified in iterable type array\.$#'
count: 1
@ -4647,11 +4642,6 @@ parameters:
count: 1
path: ../../system/Images/Handlers/BaseHandler.php
-
message: '#^Method CodeIgniter\\Images\\Handlers\\BaseHandler\:\:text\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Images/Handlers/BaseHandler.php
-
message: '#^Property CodeIgniter\\Images\\Handlers\\BaseHandler\:\:\$supportTransparency type has no value type specified in iterable type array\.$#'
count: 1
@ -4662,11 +4652,6 @@ parameters:
count: 1
path: ../../system/Images/Handlers/BaseHandler.php
-
message: '#^Method CodeIgniter\\Images\\Handlers\\ImageMagickHandler\:\:_text\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Images/Handlers/ImageMagickHandler.php
-
message: '#^Method CodeIgniter\\Images\\Handlers\\ImageMagickHandler\:\:process\(\) return type has no value type specified in iterable type array\.$#'
count: 1
@ -4677,11 +4662,6 @@ parameters:
count: 1
path: ../../system/Images/Image.php
-
message: '#^Method CodeIgniter\\Images\\ImageHandlerInterface\:\:text\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Images/ImageHandlerInterface.php
-
message: '#^Method CodeIgniter\\Language\\Language\:\:formatMessage\(\) has parameter \$message with no value type specified in iterable type array\.$#'
count: 1

View File

@ -1,8 +0,0 @@
# total 1 error
parameters:
ignoreErrors:
-
message: '#^Cannot unset offset string on list\<int\>\|null\.$#'
count: 2
path: ../../system/Test/Mock/MockCache.php