Fix some PHP 8.1 deprecation warnings

* Fix passing null to str_replace and preg_replace in HttpSocket
* Fix dynamic props usage in ModelValidator
* Fix passing null to rawurlencode in CakeRoute
This commit is contained in:
Juan Cruz Vincenti 2024-01-09 16:35:08 -03:00 committed by Kamil Wylegala
parent 2eeb1f6476
commit 84cfdfb0c3
3 changed files with 6 additions and 5 deletions

View file

@ -31,6 +31,7 @@ App::uses('Hash', 'Utility');
* @package Cake.Model * @package Cake.Model
* @link https://book.cakephp.org/2.0/en/data-validation.html * @link https://book.cakephp.org/2.0/en/data-validation.html
*/ */
#[\AllowDynamicProperties]
class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
/** /**

View file

@ -720,7 +720,7 @@ class HttpSocket extends CakeSocket {
return false; return false;
} }
$uri['path'] = preg_replace('/^\//', null, $uri['path']); $uri['path'] = preg_replace('/^\//', '', $uri['path']);
$uri['query'] = http_build_query($uri['query'], '', '&'); $uri['query'] = http_build_query($uri['query'], '', '&');
$uri['query'] = rtrim($uri['query'], '='); $uri['query'] = rtrim($uri['query'], '=');
$stripIfEmpty = array( $stripIfEmpty = array(
@ -732,16 +732,16 @@ class HttpSocket extends CakeSocket {
foreach ($stripIfEmpty as $key => $strip) { foreach ($stripIfEmpty as $key => $strip) {
if (empty($uri[$key])) { if (empty($uri[$key])) {
$uriTemplate = str_replace($strip, null, $uriTemplate); $uriTemplate = str_replace($strip, '', $uriTemplate);
} }
} }
$defaultPorts = array('http' => 80, 'https' => 443); $defaultPorts = array('http' => 80, 'https' => 443);
if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) { if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) {
$uriTemplate = str_replace(':%port', null, $uriTemplate); $uriTemplate = str_replace(':%port', '', $uriTemplate);
} }
foreach ($uri as $property => $value) { foreach ($uri as $property => $value) {
$uriTemplate = str_replace('%' . $property, $value, $uriTemplate); $uriTemplate = str_replace('%' . $property, (string)$value, $uriTemplate);
} }
if ($uriTemplate === '/*') { if ($uriTemplate === '/*') {

View file

@ -498,7 +498,7 @@ class CakeRoute {
} }
if (is_array($params['pass'])) { if (is_array($params['pass'])) {
$params['pass'] = implode('/', array_map('rawurlencode', $params['pass'])); $params['pass'] = implode('/', array_map(fn($param) => rawurlencode((string)$param), $params['pass']));
} }
$namedConfig = Router::namedConfig(); $namedConfig = Router::namedConfig();