From 0b7c075d53d217714dc4092854bfacf60e1dc9c5 Mon Sep 17 00:00:00 2001 From: reznikartem Date: Tue, 28 Apr 2020 12:05:17 +0200 Subject: [PATCH 1/3] Fix return type in model setters. Previously return type was same, as method arguments. It`s wrong, and cause errors like "Return value of Foo::setSuccess() must be of the type bool, object returned" We cant use self and current {{classname}} as return type, because that can break class inheritance. So, better remove type hint on setters, until PHP-devs dont make realization for return static --- .../src/main/resources/php-symfony/model_generic.mustache | 2 +- .../petstore/php-symfony/SymfonyBundle-php/Model/Order.php | 2 +- .../petstore/php-symfony/SymfonyBundle-php/Model/Pet.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache index 15b9cedab671..54b34b9f903d 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache @@ -35,7 +35,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} * * @return $this */ - public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}){{#vendorExtensions.x-parameter-type}}: {{^required}}?{{/required}}{{vendorExtensions.x-parameter-type}}{{/vendorExtensions.x-parameter-type}} + public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}) { $this->{{name}} = ${{name}}; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index 1dce20ccc27a..c79445f90cfd 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -197,7 +197,7 @@ public function getShipDate(): ?\DateTime * * @return $this */ - public function setShipDate(\DateTime $shipDate = null): ?\DateTime + public function setShipDate(\DateTime $shipDate = null) { $this->shipDate = $shipDate; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index cd9d321ca4af..d97cfb942a4a 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -155,7 +155,7 @@ public function getCategory(): ?Category * * @return $this */ - public function setCategory(Category $category = null): ?Category + public function setCategory(Category $category = null) { $this->category = $category; @@ -203,7 +203,7 @@ public function getPhotoUrls(): array * * @return $this */ - public function setPhotoUrls(array $photoUrls): array + public function setPhotoUrls(array $photoUrls) { $this->photoUrls = $photoUrls; @@ -227,7 +227,7 @@ public function getTags(): ?array * * @return $this */ - public function setTags(array $tags = null): ?array + public function setTags(array $tags = null) { $this->tags = $tags; From 07dd97158f9fd0eea9e6160caf97054850e16415 Mon Sep 17 00:00:00 2001 From: reznikartem Date: Wed, 29 Apr 2020 16:37:09 +0200 Subject: [PATCH 2/3] Add return self type hint for setters --- .../resources/php-symfony/model_generic.mustache | 2 +- .../SymfonyBundle-php/Model/ApiResponse.php | 6 +++--- .../SymfonyBundle-php/Model/Category.php | 4 ++-- .../SymfonyBundle-php/Model/Order.php | 12 ++++++------ .../php-symfony/SymfonyBundle-php/Model/Pet.php | 12 ++++++------ .../php-symfony/SymfonyBundle-php/Model/Tag.php | 4 ++-- .../php-symfony/SymfonyBundle-php/Model/User.php | 16 ++++++++-------- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache index 54b34b9f903d..d8beef5b8db6 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache @@ -35,7 +35,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} * * @return $this */ - public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}) + public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}): self { $this->{{name}} = ${{name}}; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php index 3c541cc76f9f..7e9a4f55b072 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -95,7 +95,7 @@ public function getCode() * * @return $this */ - public function setCode($code = null) + public function setCode($code = null): self { $this->code = $code; @@ -119,7 +119,7 @@ public function getType() * * @return $this */ - public function setType($type = null) + public function setType($type = null): self { $this->type = $type; @@ -143,7 +143,7 @@ public function getMessage() * * @return $this */ - public function setMessage($message = null) + public function setMessage($message = null): self { $this->message = $message; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php index b4c6f965236e..db6fe732a460 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -86,7 +86,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId($id = null): self { $this->id = $id; @@ -110,7 +110,7 @@ public function getName() * * @return $this */ - public function setName($name = null) + public function setName($name = null): self { $this->name = $name; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index c79445f90cfd..8f7eda92510f 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -125,7 +125,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId($id = null): self { $this->id = $id; @@ -149,7 +149,7 @@ public function getPetId() * * @return $this */ - public function setPetId($petId = null) + public function setPetId($petId = null): self { $this->petId = $petId; @@ -173,7 +173,7 @@ public function getQuantity() * * @return $this */ - public function setQuantity($quantity = null) + public function setQuantity($quantity = null): self { $this->quantity = $quantity; @@ -197,7 +197,7 @@ public function getShipDate(): ?\DateTime * * @return $this */ - public function setShipDate(\DateTime $shipDate = null) + public function setShipDate(\DateTime $shipDate = null): self { $this->shipDate = $shipDate; @@ -221,7 +221,7 @@ public function getStatus() * * @return $this */ - public function setStatus($status = null) + public function setStatus($status = null): self { $this->status = $status; @@ -245,7 +245,7 @@ public function isComplete() * * @return $this */ - public function setComplete($complete = null) + public function setComplete($complete = null): self { $this->complete = $complete; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index d97cfb942a4a..517c7f9b2c2a 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -131,7 +131,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId($id = null): self { $this->id = $id; @@ -155,7 +155,7 @@ public function getCategory(): ?Category * * @return $this */ - public function setCategory(Category $category = null) + public function setCategory(Category $category = null): self { $this->category = $category; @@ -179,7 +179,7 @@ public function getName() * * @return $this */ - public function setName($name) + public function setName($name): self { $this->name = $name; @@ -203,7 +203,7 @@ public function getPhotoUrls(): array * * @return $this */ - public function setPhotoUrls(array $photoUrls) + public function setPhotoUrls(array $photoUrls): self { $this->photoUrls = $photoUrls; @@ -227,7 +227,7 @@ public function getTags(): ?array * * @return $this */ - public function setTags(array $tags = null) + public function setTags(array $tags = null): self { $this->tags = $tags; @@ -251,7 +251,7 @@ public function getStatus() * * @return $this */ - public function setStatus($status = null) + public function setStatus($status = null): self { $this->status = $status; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php index 404309c82618..5efe10669ce3 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -86,7 +86,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId($id = null): self { $this->id = $id; @@ -110,7 +110,7 @@ public function getName() * * @return $this */ - public function setName($name = null) + public function setName($name = null): self { $this->name = $name; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php index b79d83bf0c2e..01bdec610972 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -142,7 +142,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId($id = null): self { $this->id = $id; @@ -166,7 +166,7 @@ public function getUsername() * * @return $this */ - public function setUsername($username = null) + public function setUsername($username = null): self { $this->username = $username; @@ -190,7 +190,7 @@ public function getFirstName() * * @return $this */ - public function setFirstName($firstName = null) + public function setFirstName($firstName = null): self { $this->firstName = $firstName; @@ -214,7 +214,7 @@ public function getLastName() * * @return $this */ - public function setLastName($lastName = null) + public function setLastName($lastName = null): self { $this->lastName = $lastName; @@ -238,7 +238,7 @@ public function getEmail() * * @return $this */ - public function setEmail($email = null) + public function setEmail($email = null): self { $this->email = $email; @@ -262,7 +262,7 @@ public function getPassword() * * @return $this */ - public function setPassword($password = null) + public function setPassword($password = null): self { $this->password = $password; @@ -286,7 +286,7 @@ public function getPhone() * * @return $this */ - public function setPhone($phone = null) + public function setPhone($phone = null): self { $this->phone = $phone; @@ -310,7 +310,7 @@ public function getUserStatus() * * @return $this */ - public function setUserStatus($userStatus = null) + public function setUserStatus($userStatus = null): self { $this->userStatus = $userStatus; From ace7f23acba0214b76a28a3a90e4666100497bf2 Mon Sep 17 00:00:00 2001 From: reznikartem Date: Thu, 30 Apr 2020 19:46:58 +0200 Subject: [PATCH 3/3] Revert "Add return self type hint for setters" This reverts commit 07dd9715 --- .../resources/php-symfony/model_generic.mustache | 2 +- .../SymfonyBundle-php/Model/ApiResponse.php | 6 +++--- .../SymfonyBundle-php/Model/Category.php | 4 ++-- .../SymfonyBundle-php/Model/Order.php | 12 ++++++------ .../php-symfony/SymfonyBundle-php/Model/Pet.php | 12 ++++++------ .../php-symfony/SymfonyBundle-php/Model/Tag.php | 4 ++-- .../php-symfony/SymfonyBundle-php/Model/User.php | 16 ++++++++-------- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache index d8beef5b8db6..54b34b9f903d 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache @@ -35,7 +35,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} * * @return $this */ - public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}): self + public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}) { $this->{{name}} = ${{name}}; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php index 7e9a4f55b072..3c541cc76f9f 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -95,7 +95,7 @@ public function getCode() * * @return $this */ - public function setCode($code = null): self + public function setCode($code = null) { $this->code = $code; @@ -119,7 +119,7 @@ public function getType() * * @return $this */ - public function setType($type = null): self + public function setType($type = null) { $this->type = $type; @@ -143,7 +143,7 @@ public function getMessage() * * @return $this */ - public function setMessage($message = null): self + public function setMessage($message = null) { $this->message = $message; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php index db6fe732a460..b4c6f965236e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -86,7 +86,7 @@ public function getId() * * @return $this */ - public function setId($id = null): self + public function setId($id = null) { $this->id = $id; @@ -110,7 +110,7 @@ public function getName() * * @return $this */ - public function setName($name = null): self + public function setName($name = null) { $this->name = $name; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index 8f7eda92510f..c79445f90cfd 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -125,7 +125,7 @@ public function getId() * * @return $this */ - public function setId($id = null): self + public function setId($id = null) { $this->id = $id; @@ -149,7 +149,7 @@ public function getPetId() * * @return $this */ - public function setPetId($petId = null): self + public function setPetId($petId = null) { $this->petId = $petId; @@ -173,7 +173,7 @@ public function getQuantity() * * @return $this */ - public function setQuantity($quantity = null): self + public function setQuantity($quantity = null) { $this->quantity = $quantity; @@ -197,7 +197,7 @@ public function getShipDate(): ?\DateTime * * @return $this */ - public function setShipDate(\DateTime $shipDate = null): self + public function setShipDate(\DateTime $shipDate = null) { $this->shipDate = $shipDate; @@ -221,7 +221,7 @@ public function getStatus() * * @return $this */ - public function setStatus($status = null): self + public function setStatus($status = null) { $this->status = $status; @@ -245,7 +245,7 @@ public function isComplete() * * @return $this */ - public function setComplete($complete = null): self + public function setComplete($complete = null) { $this->complete = $complete; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index 517c7f9b2c2a..d97cfb942a4a 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -131,7 +131,7 @@ public function getId() * * @return $this */ - public function setId($id = null): self + public function setId($id = null) { $this->id = $id; @@ -155,7 +155,7 @@ public function getCategory(): ?Category * * @return $this */ - public function setCategory(Category $category = null): self + public function setCategory(Category $category = null) { $this->category = $category; @@ -179,7 +179,7 @@ public function getName() * * @return $this */ - public function setName($name): self + public function setName($name) { $this->name = $name; @@ -203,7 +203,7 @@ public function getPhotoUrls(): array * * @return $this */ - public function setPhotoUrls(array $photoUrls): self + public function setPhotoUrls(array $photoUrls) { $this->photoUrls = $photoUrls; @@ -227,7 +227,7 @@ public function getTags(): ?array * * @return $this */ - public function setTags(array $tags = null): self + public function setTags(array $tags = null) { $this->tags = $tags; @@ -251,7 +251,7 @@ public function getStatus() * * @return $this */ - public function setStatus($status = null): self + public function setStatus($status = null) { $this->status = $status; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php index 5efe10669ce3..404309c82618 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -86,7 +86,7 @@ public function getId() * * @return $this */ - public function setId($id = null): self + public function setId($id = null) { $this->id = $id; @@ -110,7 +110,7 @@ public function getName() * * @return $this */ - public function setName($name = null): self + public function setName($name = null) { $this->name = $name; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php index 01bdec610972..b79d83bf0c2e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -142,7 +142,7 @@ public function getId() * * @return $this */ - public function setId($id = null): self + public function setId($id = null) { $this->id = $id; @@ -166,7 +166,7 @@ public function getUsername() * * @return $this */ - public function setUsername($username = null): self + public function setUsername($username = null) { $this->username = $username; @@ -190,7 +190,7 @@ public function getFirstName() * * @return $this */ - public function setFirstName($firstName = null): self + public function setFirstName($firstName = null) { $this->firstName = $firstName; @@ -214,7 +214,7 @@ public function getLastName() * * @return $this */ - public function setLastName($lastName = null): self + public function setLastName($lastName = null) { $this->lastName = $lastName; @@ -238,7 +238,7 @@ public function getEmail() * * @return $this */ - public function setEmail($email = null): self + public function setEmail($email = null) { $this->email = $email; @@ -262,7 +262,7 @@ public function getPassword() * * @return $this */ - public function setPassword($password = null): self + public function setPassword($password = null) { $this->password = $password; @@ -286,7 +286,7 @@ public function getPhone() * * @return $this */ - public function setPhone($phone = null): self + public function setPhone($phone = null) { $this->phone = $phone; @@ -310,7 +310,7 @@ public function getUserStatus() * * @return $this */ - public function setUserStatus($userStatus = null): self + public function setUserStatus($userStatus = null) { $this->userStatus = $userStatus;