Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvsk committed Feb 22, 2023
1 parent e26d0d8 commit 6a0ead3
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion example/php7.4/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected static function processors(string $key): \Generator
public static function create(array $data): self
{
// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php7.4/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function create(array $data): self
$data += static::defaults();

// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php7.4/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function __construct(string $name, $value)
*/
public static function cases(): array
{
return self::$map = self::$map ?: [
return self::$map = self::$map ?? [
'romance' => new self('ROMANCE', 'romance'),
'comedy' => new self('COMEDY', 'comedy'),
'drama' => new self('DRAMA', 'drama'),
Expand Down
2 changes: 1 addition & 1 deletion example/php7.4/ScienceBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function create(array $data): self
$data += static::defaults();

// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php8.0/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected static function processors(string $key): \Generator
public static function create(array $data): self
{
// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php8.0/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function create(array $data): self
$data += static::defaults();

// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php8.0/ScienceBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function create(array $data): self
$data += static::defaults();

// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php8.1/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected static function processors(string $key): \Generator
public static function create(array $data): self
{
// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php8.1/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function create(array $data): self
$data += static::defaults();

// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion example/php8.1/ScienceBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function create(array $data): self
$data += static::defaults();

// check required
if ($diff = array_diff(array_keys($data), static::required())) {
if ($diff = array_diff(static::required(), array_keys($data))) {
throw new \InvalidArgumentException("missing keys: " . implode(", ", $diff));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Builder/Class/CreateMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function build(Dto $object, PhpNamespace $ns, ClassType $class): void
if ($class->hasMethod(RequiredMethodBuilder::METHOD_NAME)) {
$creator
->addBody('// check required')
->addBody('if ($diff = array_diff(array_keys($data), static::?())) {', [RequiredMethodBuilder::METHOD_NAME])
->addBody('if ($diff = array_diff(static::?(), array_keys($data))) {', [RequiredMethodBuilder::METHOD_NAME])
->addBody(' throw new \\InvalidArgumentException("missing keys: " . implode(", ", $diff));')
->addBody('}')
->addBody('');
Expand Down
4 changes: 1 addition & 3 deletions src/Generator/Builder/EnumLegacyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public function build(Enum $enum, PhpNamespace $ns): EnumType|ClassType
$casesMap[$value] = new Literal('new self(?, ?)', [$case, $value]);
}

$casesMethod->addBody('return self::$map = self::$map \?: ?;', [
$casesMap,
]);
$casesMethod->addBody('return self::$map = self::$map \?\? ?;', [$casesMap]);

$class->addImplement('\\JsonSerializable');
$class->addMethod('jsonSerialize')
Expand Down

0 comments on commit 6a0ead3

Please sign in to comment.