Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3682,29 +3682,25 @@ public static function maybe_unserialize_array( $value ) {
* Decode a JSON string.
* Do not switch shortcodes like [24] to array unless intentional ie XML values.
*
* @param mixed $string
* @param bool $single_to_array
* @param array|string|null $string
* @param bool $single_to_array
*
* @return mixed
* @return array|string|null
*/
public static function maybe_json_decode( $string, $single_to_array = true ) {
if ( is_array( $string ) || is_null( $string ) ) {
return $string;
}

$new_string = json_decode( $string, true );

if ( function_exists( 'json_last_error' ) ) {
// php 5.3+
$single_value = false;
$new_string = json_decode( $string, true );
$single_value = false;

if ( ! $single_to_array ) {
$single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
}
if ( ! $single_to_array ) {
$single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
}

if ( json_last_error() === JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
$string = $new_string;
}
if ( json_last_error() === JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
$string = $new_string;
}

return $string;
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,14 @@
<PossiblyNullArrayAccess>
<errorLevel type="suppress">
<file name="classes/controllers/FrmStylesController.php" />
<file name="classes/helpers/FrmXMLHelper.php" />
</errorLevel>
</PossiblyNullArrayAccess>
<PossiblyNullArrayAssignment>
<errorLevel type="suppress">
<file name="classes/helpers/FrmXMLHelper.php" />
</errorLevel>
</PossiblyNullArrayAssignment>
<PossiblyNullIterator>
<errorLevel type="suppress">
<file name="classes/models/FrmPersonalData.php" />
Expand Down
Loading