From cc74b596379129ee39fa8c4671705ce240833158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pe=C5=A1ek?= Date: Fri, 18 Aug 2023 15:06:12 +0200 Subject: [PATCH] feat(#46): get rid of (some) PHP deprecation warnings - use issets, default local var values, better/newer language constructs --- lib/Cake/Model/Behavior/ContainableBehavior.php | 1 + lib/Cake/Model/Datasource/Database/Mysql.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 9 +++++---- lib/Cake/Utility/CakeText.php | 2 +- lib/Cake/Utility/Inflector.php | 2 +- lib/Cake/View/Helper.php | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Model/Behavior/ContainableBehavior.php b/lib/Cake/Model/Behavior/ContainableBehavior.php index 57ae597da..5eaf179b5 100644 --- a/lib/Cake/Model/Behavior/ContainableBehavior.php +++ b/lib/Cake/Model/Behavior/ContainableBehavior.php @@ -370,6 +370,7 @@ class ContainableBehavior extends ModelBehavior { */ public function fieldDependencies(Model $Model, $map, $fields = array()) { if ($fields === false) { + $fields = []; foreach ($map as $parent => $children) { foreach ($children as $type => $bindings) { foreach ($bindings as $dependency) { diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index fb8a3455e..000a19ea9 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -838,7 +838,7 @@ class Mysql extends DboSource { */ public function value($data, $column = null, $null = true) { $value = parent::value($data, $column, $null); - if (is_numeric($value) && substr($column, 0, 3) === 'set') { + if (is_numeric($value) && $column !== null && str_starts_with($column, 'set')) { return $this->_connection->quote($value); } return $value; diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index f87bf6ff5..0322668ee 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3270,15 +3270,16 @@ class DboSource extends DataSource { } $sign = isset($result[3]); + if ($length === null) { + // prevent deprecation warnings + return null; + } + $isFloat = in_array($type, array('dec', 'decimal', 'float', 'numeric', 'double')); if ($isFloat && strpos($length, ',') !== false) { return $length; } - if ($length === null) { - return null; - } - if (isset($types[$type])) { return (int)$length; } diff --git a/lib/Cake/Utility/CakeText.php b/lib/Cake/Utility/CakeText.php index 9fc3a65e8..cf427ed6e 100644 --- a/lib/Cake/Utility/CakeText.php +++ b/lib/Cake/Utility/CakeText.php @@ -193,7 +193,7 @@ class CakeText { $dataReplacements = array_combine($hashKeys, array_values($data)); foreach ($dataReplacements as $tmpHash => $tmpValue) { $tmpValue = (is_array($tmpValue)) ? '' : $tmpValue; - $str = str_replace($tmpHash, $tmpValue, $str); + $str = str_replace($tmpHash, $tmpValue ?? '', $str); } if (!isset($options['format']) && isset($options['before'])) { diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 80c5c09ae..d0ec62f47 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -483,7 +483,7 @@ class Inflector { */ public static function underscore($camelCasedWord) { if (!($result = static::_cache(__FUNCTION__, $camelCasedWord))) { - $underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord); + $underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord ?? ''); $result = mb_strtolower($underscoredWord); static::_cache(__FUNCTION__, $camelCasedWord, $result); } diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index ac8faf818..5ed869461 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -573,7 +573,7 @@ class Helper extends CakeObject { if ($setScope === true) { $this->_modelScope = $entity; } - $parts = array_values(Hash::filter(explode('.', $entity))); + $parts = $entity !== null ? array_values(Hash::filter(explode('.', $entity))) : []; if (empty($parts)) { return; }