Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	utils/phpstan-baseline/missingType.iterableValue.neon
  • Loading branch information
michalsn committed Jan 6, 2025
2 parents cc96fe3 + 61741c5 commit c3bfac5
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 114 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public static function promptByKey($text, array $options, $validation = null): s

CLI::isZeroOptions($options);

if ($line = array_shift($text)) {
if (($line = array_shift($text)) !== null) {
CLI::write($line);
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
// 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();

Expand Down
8 changes: 4 additions & 4 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public function join(string $table, $cond, string $type = '', ?bool $escape = nu
} 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]);
Expand Down Expand Up @@ -2203,7 +2203,7 @@ protected function formatValues(array $values): array
*
* @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)
{
Expand Down Expand Up @@ -3477,7 +3477,7 @@ protected function getOperator(string $str, bool $list = false)
'/' . implode('|', $this->pregOperators) . '/i',
$str,
$match
) ? ($list ? $match[0] : $match[0][0]) : false;
) >= 1 ? ($list ? $match[0] : $match[0][0]) : false;
}

/**
Expand Down Expand Up @@ -3508,7 +3508,7 @@ private function getOperatorFromWhereKey(string $whereKey)
'/' . implode('|', $pregOperators) . '/i',
$whereKey,
$match
) ? $match[0] : false;
) >= 1 ? $match[0] : false;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ protected function getDriverFunctionPrefix(): string
*/
public function affectedRows(): int
{
if ($this->resultID === false) {
return 0;
}

return pg_affected_rows($this->resultID);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ protected function matchNamedBinds(string $sql, array $binds): string
*/
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
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function join(string $table, $cond, string $type = '', ?bool $escape = nu
$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]);
Expand Down
4 changes: 4 additions & 0 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ public function error(): array
*/
public function affectedRows(): int
{
if ($this->resultID === false) {
return 0;
}

return sqlsrv_rows_affected($this->resultID);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ public function wordWrap($str, $charlim = null)

$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);
Expand Down
6 changes: 3 additions & 3 deletions system/Helpers/text_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function ascii_to_entities(string $str): string
*/
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 = '';
Expand Down Expand Up @@ -196,7 +196,7 @@ function word_censor(string $str, array $censored, string $replacement = ''): st
"\\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--) {
Expand Down Expand Up @@ -352,7 +352,7 @@ function word_wrap(string $str, int $charlim = 76): string
// 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);
Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ function auto_link(string $str, string $type = 'both', bool $popup = false): str
$str,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) >= 1
) {
// Set our target HTML if using popup links.
$target = ($popup) ? ' target="_blank"' : '';
Expand All @@ -387,7 +387,7 @@ function auto_link(string $str, string $type = 'both', bool $popup = false): str
$str,
$matches,
PREG_OFFSET_CAPTURE
)
) >= 1
) {
foreach (array_reverse($matches[0]) as $match) {
if (filter_var($match[0], FILTER_VALIDATE_EMAIL) !== false) {
Expand Down
32 changes: 15 additions & 17 deletions system/Images/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,23 +396,6 @@ public function flip(string $dir = 'vertical')
*/
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);
Expand All @@ -427,6 +410,21 @@ public function text(string $text, array $options = [])
/**
* 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 = []);
Expand Down
2 changes: 0 additions & 2 deletions system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ protected function supportedFormatCheck()
/**
* Handler-specific method for overlaying text on an image.
*
* @return void
*
* @throws Exception
*/
protected function _text(string $text, array $options = [])
Expand Down
20 changes: 15 additions & 5 deletions system/Images/ImageHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,21 @@ public function fit(int $width, int $height, string $position);
* - 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
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function open($path, $name): bool
$this->savePath,
$matches,
PREG_SET_ORDER
) === 0
) < 1
) {
$this->memcached = null;
$this->logger->error('Session: Invalid Memcached save path format: ' . $this->savePath);
Expand Down
2 changes: 1 addition & 1 deletion system/Test/Mock/MockCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MockCache extends BaseHandler implements CacheInterface
/**
* Expiration times.
*
* @var ?list<int>
* @var array<string, int|null>
*/
protected $expirations = [];

Expand Down
2 changes: 1 addition & 1 deletion system/Typography/Typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str

// 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);
Expand Down
4 changes: 2 additions & 2 deletions system/View/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ protected function extractNoparse(string $template): string
* $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]);
Expand Down Expand Up @@ -691,7 +691,7 @@ protected function parsePlugins(string $template)
* $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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function foo_bar_baz(): string
}
}

$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
Expand Down
3 changes: 2 additions & 1 deletion tests/system/Database/Builder/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;

Expand Down Expand Up @@ -82,7 +83,7 @@ public function testSelectAcceptsArrayWithRawSql(array $select, string $expected
}

/**
* @return list<list<RawSql|string>|string>
* @return Generator<list<RawSql|string>|string>
*/
public static function provideSelectAcceptsArrayWithRawSql(): iterable
{
Expand Down
31 changes: 30 additions & 1 deletion tests/system/Database/Live/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\Database\Live;

use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Forge;
use CodeIgniter\Database\RawSql;
use CodeIgniter\Test\CIUnitTestCase;
Expand Down Expand Up @@ -79,13 +80,41 @@ public function testInsertBatch(): void
],
];

$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 = [
Expand Down
Loading

0 comments on commit c3bfac5

Please sign in to comment.