Skip to content

Commit

Permalink
Fix warnings for unset params
Browse files Browse the repository at this point in the history
Adds new utility function to evaluate boolean-type values, which ensures only set params are accessed; applies this function to the two vars in the textarea input opts config file that were throwing php warnings. Note that the new function will be applicable to other config files.
  • Loading branch information
smg6511 committed May 31, 2024
1 parent 213f6f4 commit 98d07e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# Set values
$defaultHeight = 140;
$inputHeight = !empty($params['inputHeight']) ? $params['inputHeight'] : $defaultHeight ;
$textareaGrow = $params['textareaGrow'] === 'true' || $params['textareaGrow'] == 1 ? 'true' : 'false' ;
$textareaResizable = $params['textareaResizable'] === 'true' || $params['textareaResizable'] == 1 ? 'true' : 'false' ;
$textareaGrow = $this->modx->paramValueIsTrue($params, 'textareaGrow', true);
$textareaResizable = $this->modx->paramValueIsTrue($params, 'textareaResizable', true);

# Set help descriptions
$descKeys = [
Expand Down
17 changes: 17 additions & 0 deletions core/src/Revolution/modX.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ public static function toQueryString(array $parameters = [], $numPrefix = '', $a
return http_build_query($parameters, $numPrefix, $argSeparator);
}

/**
* Evaluate boolean-like parameter value and return it as an actual boolean or as a string; a string may be
* needed/preferred when building code blocks (e.g., javascript) via php strings (nowdoc/heredoc ones in particular).

Check warning on line 399 in core/src/Revolution/modX.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 121 characters
*
* @param array $params An associative or numeric-indexed array of parameters
* @param string|int $key The array key to evaluate
* @param bool $returnBoolAsString Whether to return the string representation ('true' or 'false') of the boolean value

Check warning on line 403 in core/src/Revolution/modX.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 123 characters
* @return string|bool
*/
public function paramValueIsTrue(array $params, $key, bool $returnBoolAsString = false)
{
if (isset($params[$key]) && in_array($params[$key], ['true', true, '1', 1])) {
return $returnBoolAsString ? 'true' : true ;
}
return $returnBoolAsString ? 'false' : false ;
}

/**
* Create, retrieve, or update specific modX instances.
*
Expand Down

0 comments on commit 98d07e5

Please sign in to comment.