Skip to content

Commit

Permalink
php set default null
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 6, 2024
1 parent b7cc086 commit 8d530e8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 73 deletions.
2 changes: 2 additions & 0 deletions src/Generator/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ protected function writeStruct(Code\Name $name, array $properties, ?string $exte
$prop->addAttribute($attribute);
}

$prop->setDefault(null);

$class->addStmt($prop);

$setter = $this->factory->method($property->getName()->getMethod(prefix: ['set']));
Expand Down
54 changes: 27 additions & 27 deletions tests/Generator/resource/php/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#[Description('Location of the person')]
class Location implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?float $lat;
protected ?float $long;
protected ?float $lat = null;
protected ?float $long = null;
public function setLat(?float $lat) : void
{
$this->lat = $lat;
Expand Down Expand Up @@ -41,20 +41,20 @@ public function jsonSerialize() : object
#[Description('An simple author element with some description')]
class Author implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?string $title;
protected ?string $title = null;
#[Description('We will send no spam to this address')]
#[Nullable(true)]
protected ?string $email;
protected ?string $email = null;
/**
* @var array<string>|null
*/
protected ?array $categories;
protected ?array $categories = null;
/**
* @var array<Location>|null
*/
#[Description('Array of locations')]
protected ?array $locations;
protected ?Location $origin;
protected ?array $locations = null;
protected ?Location $origin = null;
public function setTitle(?string $title) : void
{
$this->title = $title;
Expand Down Expand Up @@ -138,47 +138,47 @@ class Meta extends \ArrayObject
#[Description('An general news entry')]
class News implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?Meta $config;
protected ?Meta $config = null;
/**
* @var \PSX\Record\Record|null
*/
protected ?\PSX\Record\Record $inlineConfig;
protected ?\PSX\Record\Record $inlineConfig = null;
/**
* @var \PSX\Record\Record|null
*/
protected ?\PSX\Record\Record $mapTags;
protected ?\PSX\Record\Record $mapTags = null;
/**
* @var \PSX\Record\Record|null
*/
protected ?\PSX\Record\Record $mapReceiver;
protected ?\PSX\Record\Record $mapReceiver = null;
/**
* @var array<string>|null
*/
protected ?array $tags;
protected ?array $tags = null;
/**
* @var array<Author>|null
*/
protected ?array $receiver;
protected ?bool $read;
protected ?Author $author;
protected ?Meta $meta;
protected ?array $receiver = null;
protected ?bool $read = null;
protected ?Author $author = null;
protected ?Meta $meta = null;
#[Format('date')]
protected ?\PSX\DateTime\LocalDate $sendDate;
protected ?\PSX\DateTime\LocalDate $sendDate = null;
#[Format('date-time')]
protected ?\PSX\DateTime\LocalDateTime $readDate;
protected ?float $price;
protected ?int $rating;
protected ?\PSX\DateTime\LocalDateTime $readDate = null;
protected ?float $price = null;
protected ?int $rating = null;
#[Description('Contains the main content of the news entry')]
protected ?string $content;
protected ?string $question;
protected ?string $version;
protected ?string $content = null;
protected ?string $question = null;
protected ?string $version = null;
#[Format('time')]
protected ?\PSX\DateTime\LocalTime $coffeeTime;
protected ?\PSX\DateTime\LocalTime $coffeeTime = null;
#[Key('g-recaptcha-response')]
protected ?string $captcha;
protected ?string $captcha = null;
#[Key('media.fields')]
protected ?string $mediaFields;
protected mixed $payload;
protected ?string $mediaFields = null;
protected mixed $payload = null;
public function setConfig(?Meta $config) : void
{
$this->config = $config;
Expand Down
72 changes: 36 additions & 36 deletions tests/Generator/resource/php/php_complex.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
abstract class DefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $description;
protected ?string $description = null;
#[Description('')]
protected ?bool $deprecated;
protected ?bool $deprecated = null;
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setDescription(?string $description) : void
{
$this->description = $description;
Expand Down Expand Up @@ -60,28 +60,28 @@ public function jsonSerialize() : object
class StructDefinitionType extends DefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('The parent type of this struct. The struct inherits all properties from the parent type')]
protected ?string $parent;
protected ?string $parent = null;
#[Description('Indicates that this struct is a base type, this means it is an abstract type which is used by different types as parent')]
protected ?bool $base;
protected ?bool $base = null;
/**
* @var \PSX\Record\Record|null
*/
#[Description('')]
protected ?\PSX\Record\Record $properties;
protected ?\PSX\Record\Record $properties = null;
#[Description('In case this is a base type it is possible to specify a discriminator property')]
protected ?string $discriminator;
protected ?string $discriminator = null;
/**
* @var \PSX\Record\Record|null
*/
#[Description('In case a discriminator property was set it is possible to specify a mapping. The key is the type name and the value the concrete value which is mapped to the type')]
protected ?\PSX\Record\Record $mapping;
protected ?\PSX\Record\Record $mapping = null;
/**
* @var \PSX\Record\Record|null
*/
#[Description('In case the parent type contains generics it is possible to set a concrete type for each generic type')]
protected ?\PSX\Record\Record $template;
protected ?\PSX\Record\Record $template = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -168,9 +168,9 @@ public function jsonSerialize() : object
abstract class CollectionDefinitionType extends DefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('')]
protected ?PropertyType $schema;
protected ?PropertyType $schema = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -207,7 +207,7 @@ public function jsonSerialize() : object
class MapDefinitionType extends CollectionDefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -235,7 +235,7 @@ public function jsonSerialize() : object
class ArrayDefinitionType extends CollectionDefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -275,13 +275,13 @@ public function jsonSerialize() : object
abstract class PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $description;
protected ?string $description = null;
#[Description('')]
protected ?bool $deprecated;
protected ?bool $deprecated = null;
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('')]
protected ?bool $nullable;
protected ?bool $nullable = null;
public function setDescription(?string $description) : void
{
$this->description = $description;
Expand Down Expand Up @@ -343,7 +343,7 @@ public function jsonSerialize() : object
abstract class ScalarPropertyType extends PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -371,7 +371,7 @@ public function jsonSerialize() : object
class IntegerPropertyType extends ScalarPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -399,7 +399,7 @@ public function jsonSerialize() : object
class NumberPropertyType extends ScalarPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -427,9 +427,9 @@ public function jsonSerialize() : object
class StringPropertyType extends ScalarPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('')]
protected ?string $format;
protected ?string $format = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -466,7 +466,7 @@ public function jsonSerialize() : object
class BooleanPropertyType extends ScalarPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -499,9 +499,9 @@ public function jsonSerialize() : object
abstract class CollectionPropertyType extends PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('')]
protected ?PropertyType $schema;
protected ?PropertyType $schema = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -538,7 +538,7 @@ public function jsonSerialize() : object
class MapPropertyType extends CollectionPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -566,7 +566,7 @@ public function jsonSerialize() : object
class ArrayPropertyType extends CollectionPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -594,7 +594,7 @@ public function jsonSerialize() : object
class AnyPropertyType extends PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -622,9 +622,9 @@ public function jsonSerialize() : object
class GenericPropertyType extends PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('The generic name, it is recommended to use typical generics names like T or TValue')]
protected ?string $name;
protected ?string $name = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -661,9 +661,9 @@ public function jsonSerialize() : object
class ReferencePropertyType extends PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?string $type;
protected ?string $type = null;
#[Description('Name of the target reference, must a key from the definitions map')]
protected ?string $target;
protected ?string $target = null;
public function setType(?string $type) : void
{
$this->type = $type;
Expand Down Expand Up @@ -703,14 +703,14 @@ class Specification implements \JsonSerializable, \PSX\Record\RecordableInterfac
* @var \PSX\Record\Record|null
*/
#[Description('')]
protected ?\PSX\Record\Record $import;
protected ?\PSX\Record\Record $import = null;
/**
* @var \PSX\Record\Record|null
*/
#[Description('')]
protected ?\PSX\Record\Record $definitions;
protected ?\PSX\Record\Record $definitions = null;
#[Description('')]
protected ?string $root;
protected ?string $root = null;
public function setImport(?\PSX\Record\Record $import) : void
{
$this->import = $import;
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/resource/php/php_import.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Import implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?StudentMap $students;
protected ?Student $student;
protected ?StudentMap $students = null;
protected ?Student $student = null;
public function setStudents(?StudentMap $students) : void
{
$this->students = $students;
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/resource/php/php_import_ns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class Import implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?\My\Import\StudentMap $students;
protected ?\My\Import\Student $student;
protected ?\My\Import\StudentMap $students = null;
protected ?\My\Import\Student $student = null;
public function setStudents(?\My\Import\StudentMap $students) : void
{
$this->students = $students;
Expand Down
Loading

0 comments on commit 8d530e8

Please sign in to comment.