Skip to content

Commit

Permalink
rex_api_result: Nicht über alle Properties iterieren (#6018)
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Mar 10, 2024
1 parent 06890b3 commit 8e057a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
5 changes: 0 additions & 5 deletions .tools/phpstan/baseline.neon
Expand Up @@ -1350,11 +1350,6 @@ parameters:
count: 1
path: ../../redaxo/src/addons/users/lib/role.php

-
message: "#^Argument of an invalid type rex_api_result supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../../redaxo/src/core/lib/api_function.php

-
message: "#^Parameter \\#1 \\$callback of function spl_autoload_register expects \\(callable\\(string\\)\\: void\\)\\|null, Closure\\(string\\)\\: bool given\\.$#"
count: 1
Expand Down
3 changes: 0 additions & 3 deletions .tools/psalm/baseline.xml
Expand Up @@ -3329,9 +3329,6 @@
<file src="redaxo/src/core/lib/api_function.php">
<MixedAssignment>
<code><![CDATA[$json]]></code>
<code><![CDATA[$key]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[new $apiClass()]]></code>
Expand Down
5 changes: 0 additions & 5 deletions psalm.xml
Expand Up @@ -73,11 +73,6 @@
<MissingClosureReturnType errorLevel="info" />
<MissingParamType errorLevel="info" />
<PropertyNotSetInConstructor errorLevel="info" />
<RawObjectIteration>
<errorLevel type="info">
<file name="redaxo/src/core/lib/api_function.php"/>
</errorLevel>
</RawObjectIteration>
<RedundantCastGivenDocblockType errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />
<RedundantFunctionCallGivenDocblockType errorLevel="info" />
Expand Down
18 changes: 8 additions & 10 deletions redaxo/src/core/lib/api_function.php
Expand Up @@ -360,11 +360,10 @@ public function isSuccessfull()
*/
public function toJSON()
{
$json = new stdClass();
foreach ($this as $key => $value) {
$json->$key = $value;
}
return json_encode($json);
return json_encode([
'succeeded' => $this->succeeded,
'message' => $this->message,
]);
}

/**
Expand All @@ -373,17 +372,16 @@ public function toJSON()
*/
public static function fromJSON($json)
{
$result = new self(true);
$json = json_decode($json, true);

if (!is_array($json)) {
throw new rex_exception('Unable to decode json into an array.');
}

foreach ($json as $key => $value) {
$result->$key = $value;
}
return $result;
return new self(
rex_type::bool($json['succeeded'] ?? null),
rex_type::nullOrString($json['message'] ?? null),
);
}
}

Expand Down

0 comments on commit 8e057a1

Please sign in to comment.