feat(#46): get rid of (some) PHP deprecation warnings

- use issets, default local var values, better/newer language constructs
This commit is contained in:
Jan Pešek 2023-08-18 15:06:12 +02:00 committed by Kamil Wylegala
parent de95041969
commit cc74b59637
6 changed files with 10 additions and 8 deletions

View file

@ -370,6 +370,7 @@ class ContainableBehavior extends ModelBehavior {
*/ */
public function fieldDependencies(Model $Model, $map, $fields = array()) { public function fieldDependencies(Model $Model, $map, $fields = array()) {
if ($fields === false) { if ($fields === false) {
$fields = [];
foreach ($map as $parent => $children) { foreach ($map as $parent => $children) {
foreach ($children as $type => $bindings) { foreach ($children as $type => $bindings) {
foreach ($bindings as $dependency) { foreach ($bindings as $dependency) {

View file

@ -838,7 +838,7 @@ class Mysql extends DboSource {
*/ */
public function value($data, $column = null, $null = true) { public function value($data, $column = null, $null = true) {
$value = parent::value($data, $column, $null); $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 $this->_connection->quote($value);
} }
return $value; return $value;

View file

@ -3270,15 +3270,16 @@ class DboSource extends DataSource {
} }
$sign = isset($result[3]); $sign = isset($result[3]);
if ($length === null) {
// prevent deprecation warnings
return null;
}
$isFloat = in_array($type, array('dec', 'decimal', 'float', 'numeric', 'double')); $isFloat = in_array($type, array('dec', 'decimal', 'float', 'numeric', 'double'));
if ($isFloat && strpos($length, ',') !== false) { if ($isFloat && strpos($length, ',') !== false) {
return $length; return $length;
} }
if ($length === null) {
return null;
}
if (isset($types[$type])) { if (isset($types[$type])) {
return (int)$length; return (int)$length;
} }

View file

@ -193,7 +193,7 @@ class CakeText {
$dataReplacements = array_combine($hashKeys, array_values($data)); $dataReplacements = array_combine($hashKeys, array_values($data));
foreach ($dataReplacements as $tmpHash => $tmpValue) { foreach ($dataReplacements as $tmpHash => $tmpValue) {
$tmpValue = (is_array($tmpValue)) ? '' : $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'])) { if (!isset($options['format']) && isset($options['before'])) {

View file

@ -483,7 +483,7 @@ class Inflector {
*/ */
public static function underscore($camelCasedWord) { public static function underscore($camelCasedWord) {
if (!($result = static::_cache(__FUNCTION__, $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); $result = mb_strtolower($underscoredWord);
static::_cache(__FUNCTION__, $camelCasedWord, $result); static::_cache(__FUNCTION__, $camelCasedWord, $result);
} }

View file

@ -573,7 +573,7 @@ class Helper extends CakeObject {
if ($setScope === true) { if ($setScope === true) {
$this->_modelScope = $entity; $this->_modelScope = $entity;
} }
$parts = array_values(Hash::filter(explode('.', $entity))); $parts = $entity !== null ? array_values(Hash::filter(explode('.', $entity))) : [];
if (empty($parts)) { if (empty($parts)) {
return; return;
} }