Skip to content

Commit

Permalink
trim() on null depreciated in PHP 8.1
Browse files Browse the repository at this point in the history
Added ($variable ? $variable : '') rather than ($variable ?? '') to maintain compatibility with PHP < 7
  • Loading branch information
adambinnersley authored Nov 11, 2022
1 parent 82a1772 commit dc8b087
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Modifiers/Modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Modifier
*/
public static function setNullOnEmpty($variable)
{
if (empty(trim($variable))) {
if (empty(trim($variable ? $variable : ''))) {
return null;
}
return $variable;
Expand All @@ -24,7 +24,7 @@ public static function setNullOnEmpty($variable)
*/
public static function setZeroOnEmpty($variable)
{
if (empty(trim($variable)) || (is_numeric($variable) && floatval($variable) == 0)) {
if (empty(trim($variable ? $variable : 0)) || (is_numeric($variable) && floatval($variable) == 0)) {
return 0;
}
return $variable;
Expand All @@ -37,7 +37,7 @@ public static function setZeroOnEmpty($variable)
*/
public static function isRequiredString($variable, $minStringLength = 2)
{
if (!empty(trim($variable)) && strlen(trim($variable)) >= $minStringLength) {
if (!empty(trim($variable ? $variable : '')) && strlen(trim($variable ? $variable : '')) >= $minStringLength) {
return true;
}
return false;
Expand All @@ -63,7 +63,7 @@ public static function isRequiredNumeric($variable)
*/
public static function isRequiredNonNumeric($variable)
{
if (!empty(trim($variable)) && !is_numeric($variable)) {
if (!empty(trim($variable ? $variable : '')) && !is_numeric($variable)) {
return true;
}
return false;
Expand Down

0 comments on commit dc8b087

Please sign in to comment.