Skip to content

Commit

Permalink
wrapObject=false is only for encode object
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Dec 3, 2024
1 parent 2c805b6 commit 6848b94
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 4 additions & 0 deletions generator/src/Definition/OperatorDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function __construct(
default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)),
};

if (!$wrapObject && $this->encode !== Encode::Object) {

Check failure on line 46 in generator/src/Definition/OperatorDefinition.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space after NOT operator; 0 found
throw new UnexpectedValueException(sprintf('Operator "%s" cannot have wrapObject set to false when encode is not "object"', $name));
}

// Convert arguments to ArgumentDefinition objects
// Optional arguments must be after required arguments
$requiredArgs = $optionalArgs = [];
Expand Down
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@
<code><![CDATA[$val]]></code>
<code><![CDATA[$val]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[stdClass]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$result]]></code>
</MixedReturnStatement>
<PossibleRawObjectIteration>
<code><![CDATA[$val]]></code>
</PossibleRawObjectIteration>
Expand Down
8 changes: 5 additions & 3 deletions src/Builder/Encoder/OperatorEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ private function encodeAsObject(OperatorInterface $value): stdClass
}
}

if ($value::NAME === null) {
return $result;
}

return $this->wrap($value, $result);
}

Expand All @@ -113,9 +117,7 @@ private function encodeAsSingle(OperatorInterface $value): stdClass
*/
private function wrap(OperatorInterface $value, mixed $result): stdClass
{
if ($value::NAME === null) {
return $result;
}
assert(is_string($value::NAME));

Check failure on line 120 in src/Builder/Encoder/OperatorEncoder.php

View workflow job for this annotation

GitHub Actions / phpcs

Function assert() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 120 in src/Builder/Encoder/OperatorEncoder.php

View workflow job for this annotation

GitHub Actions / phpcs

Function is_string() should not be referenced via a fallback global name, but via a use statement.

$object = new stdClass();
$object->{$value::NAME} = $result;
Expand Down

0 comments on commit 6848b94

Please sign in to comment.