diff --git a/composer.json b/composer.json index 1680f18b02d1..99b8f510c773 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index cb17fa1125af..131b880f067f 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -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); } @@ -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(); diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 9b5b87d45f6d..f5f21ed8841e 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -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]); @@ -2203,7 +2203,7 @@ protected function formatValues(array $values): array * * @param array|object|null $set a dataset * - * @return false|int|list Number of rows inserted or FALSE on failure, SQL array when testMode + * @return false|int|list 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 @@ 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; } /** @@ -3508,7 +3508,7 @@ private function getOperatorFromWhereKey(string $whereKey) '/' . implode('|', $pregOperators) . '/i', $whereKey, $match - ) ? $match[0] : false; + ) >= 1 ? $match[0] : false; } /** diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index e808930663dc..06ef62a9f842 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -228,6 +228,10 @@ protected function getDriverFunctionPrefix(): string */ public function affectedRows(): int { + if ($this->resultID === false) { + return 0; + } + return pg_affected_rows($this->resultID); } diff --git a/system/Database/Query.php b/system/Database/Query.php index 36026817d4d1..f0b75513c6b5 100644 --- a/system/Database/Query.php +++ b/system/Database/Query.php @@ -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 diff --git a/system/Database/SQLSRV/Builder.php b/system/Database/SQLSRV/Builder.php index e320069e80bf..1aeaf0a4e6ee 100644 --- a/system/Database/SQLSRV/Builder.php +++ b/system/Database/SQLSRV/Builder.php @@ -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]); diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 95f75cf44768..c8e1e3fbee12 100644 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -453,6 +453,10 @@ public function error(): array */ public function affectedRows(): int { + if ($this->resultID === false) { + return 0; + } + return sqlsrv_rows_affected($this->resultID); } diff --git a/system/Email/Email.php b/system/Email/Email.php index 5d420cc2e99c..c52c36230866 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -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); diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index a9fd182b298c..170964f532cc 100644 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -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 = ''; @@ -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--) { @@ -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); diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 28bb2cf4c2a1..b6df3edc3c3d 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -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"' : ''; @@ -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) { diff --git a/system/Images/Handlers/BaseHandler.php b/system/Images/Handlers/BaseHandler.php index 033c4e6beda7..9c263afb89d1 100644 --- a/system/Images/Handlers/BaseHandler.php +++ b/system/Images/Handlers/BaseHandler.php @@ -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); @@ -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 = []); diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index 583a2759fd31..f1448efa7f8a 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -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 = []) diff --git a/system/Images/ImageHandlerInterface.php b/system/Images/ImageHandlerInterface.php index 7cb635be3738..93b2009d6a93 100644 --- a/system/Images/ImageHandlerInterface.php +++ b/system/Images/ImageHandlerInterface.php @@ -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 */ diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index e651808a8ba8..73133e88d959 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -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); diff --git a/system/Test/Mock/MockCache.php b/system/Test/Mock/MockCache.php index 85b5fd9e7e14..b410df874243 100644 --- a/system/Test/Mock/MockCache.php +++ b/system/Test/Mock/MockCache.php @@ -31,7 +31,7 @@ class MockCache extends BaseHandler implements CacheInterface /** * Expiration times. * - * @var ?list + * @var array */ protected $expirations = []; diff --git a/system/Typography/Typography.php b/system/Typography/Typography.php index 145ff68f1193..1dfca68c5164 100644 --- a/system/Typography/Typography.php +++ b/system/Typography/Typography.php @@ -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, '