Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:*] use static return type instead of self for setters #1242

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ private function makeMethodFluent(Builder\Method $methodBuilder): void
$methodBuilder
->addStmt($this->createBlankLineNode(self::CONTEXT_CLASS_METHOD))
->addStmt(new Node\Stmt\Return_(new Node\Expr\Variable('this')));
$methodBuilder->setReturnType('self');
$methodBuilder->setReturnType('static');
}

private function isInSameNamespace(string $class): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getName(): ?string
return $this->name;
}

public function setName(string $name): self
public function setName(string $name): static
{
$this->name = $name;

Expand All @@ -50,7 +50,7 @@ public function getMagic(): ?int
return $this->magic;
}

public function setMagic(int $magic): self
public function setMagic(int $magic): static
{
$this->magic = $magic;

Expand All @@ -62,7 +62,7 @@ public function getCreator(): ?User
return $this->creator;
}

public function setCreator(?User $creator): self
public function setCreator(?User $creator): static
{
$this->creator = $creator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getEmbed(): Embed
return $this->embed;
}

public function setEmbed(Embed $embed): self
public function setEmbed(Embed $embed): static
{
$this->embed = $embed;

Expand All @@ -47,7 +47,7 @@ public function getApiKey(): ?string
return $this->apiKey;
}

public function setApiKey(string $apiKey): self
public function setApiKey(string $apiKey): static
{
$this->apiKey = $apiKey;

Expand All @@ -62,7 +62,7 @@ public function getTags(): Collection
return $this->tags;
}

public function addTag(Tag $tag): self
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
Expand All @@ -71,7 +71,7 @@ public function addTag(Tag $tag): self
return $this;
}

public function removeTag(Tag $tag): self
public function removeTag(Tag $tag): static
{
$this->tags->removeElement($tag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getVal(): ?int
return $this->val;
}

public function setVal(int $val): self
public function setVal(int $val): static
{
$this->val = $val;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getAvatars(): Collection
return $this->avatars;
}

public function addAvatar(UserAvatar $avatar): self
public function addAvatar(UserAvatar $avatar): static
{
if (!$this->avatars->contains($avatar)) {
$this->avatars->add($avatar);
Expand All @@ -63,7 +63,7 @@ public function addAvatar(UserAvatar $avatar): self
return $this;
}

public function removeAvatar(UserAvatar $avatar): self
public function removeAvatar(UserAvatar $avatar): static
{
if ($this->avatars->removeElement($avatar)) {
// set the owning side to null (unless already changed)
Expand All @@ -88,7 +88,7 @@ public function getTags(): Collection
return $this->tags;
}

public function addTag(Tag $tag): self
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
Expand All @@ -97,7 +97,7 @@ public function addTag(Tag $tag): self
return $this;
}

public function removeTag(Tag $tag): self
public function removeTag(Tag $tag): static
{
$this->tags->removeElement($tag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getUser(): ?User
return $this->user;
}

public function setUser(?User $user): self
public function setUser(?User $user): static
{
$this->user = $user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getUser(): ?User
return $this->user;
}

public function setUser(User $user): self
public function setUser(User $user): static
{
$this->user = $user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getName(): ?string
return $this->name;
}

public function setName(string $name): self
public function setName(string $name): static
{
$this->name = $name;

Expand All @@ -50,7 +50,7 @@ public function getMagic(): ?int
return $this->magic;
}

public function setMagic(int $magic): self
public function setMagic(int $magic): static
{
$this->magic = $magic;

Expand All @@ -62,7 +62,7 @@ public function getCreator(): ?User
return $this->creator;
}

public function setCreator(?User $creator): self
public function setCreator(?User $creator): static
{
$this->creator = $creator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getEmbed(): Embed
return $this->embed;
}

public function setEmbed(Embed $embed): self
public function setEmbed(Embed $embed): static
{
$this->embed = $embed;

Expand All @@ -47,7 +47,7 @@ public function getApiKey(): ?string
return $this->apiKey;
}

public function setApiKey(string $apiKey): self
public function setApiKey(string $apiKey): static
{
$this->apiKey = $apiKey;

Expand All @@ -62,7 +62,7 @@ public function getTags(): Collection
return $this->tags;
}

public function addTag(Tag $tag): self
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
Expand All @@ -71,7 +71,7 @@ public function addTag(Tag $tag): self
return $this;
}

public function removeTag(Tag $tag): self
public function removeTag(Tag $tag): static
{
$this->tags->removeElement($tag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getVal(): ?int
return $this->val;
}

public function setVal(int $val): self
public function setVal(int $val): static
{
$this->val = $val;

Expand Down
10 changes: 5 additions & 5 deletions tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function customMethod()
return '';
}

public function setUserProfile(?UserProfile $userProfile): self
public function setUserProfile(?UserProfile $userProfile): static
{
// unset the owning side of the relation if necessary
if ($userProfile === null && $this->userProfile !== null) {
Expand All @@ -64,7 +64,7 @@ public function getAvatars(): Collection
return $this->avatars;
}

public function addAvatar(UserAvatar $avatar): self
public function addAvatar(UserAvatar $avatar): static
{
if (!$this->avatars->contains($avatar)) {
$this->avatars->add($avatar);
Expand All @@ -74,7 +74,7 @@ public function addAvatar(UserAvatar $avatar): self
return $this;
}

public function removeAvatar(UserAvatar $avatar): self
public function removeAvatar(UserAvatar $avatar): static
{
if ($this->avatars->removeElement($avatar)) {
// set the owning side to null (unless already changed)
Expand All @@ -99,7 +99,7 @@ public function getTags(): Collection
return $this->tags;
}

public function addTag(Tag $tag): self
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
Expand All @@ -108,7 +108,7 @@ public function addTag(Tag $tag): self
return $this;
}

public function removeTag(Tag $tag): self
public function removeTag(Tag $tag): static
{
$this->tags->removeElement($tag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getUser(): ?User
return $this->user;
}

public function setUser(?User $user): self
public function setUser(?User $user): static
{
$this->user = $user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getUser(): ?User
return $this->user;
}

public function setUser(User $user): self
public function setUser(User $user): static
{
$this->user = $user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getUser(): ?UserXml
return $this->user;
}

public function setUser(?UserXml $user): self
public function setUser(?UserXml $user): static
{
$this->user = $user;

Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getName(): ?string
return $this->name;
}

public function setName(string $name): self
public function setName(string $name): static
{
$this->name = $name;

Expand All @@ -44,7 +44,7 @@ public function getAvatars(): Collection
return $this->avatars;
}

public function addAvatar(UserAvatar $avatar): self
public function addAvatar(UserAvatar $avatar): static
{
if (!$this->avatars->contains($avatar)) {
$this->avatars->add($avatar);
Expand All @@ -54,7 +54,7 @@ public function addAvatar(UserAvatar $avatar): self
return $this;
}

public function removeAvatar(UserAvatar $avatar): self
public function removeAvatar(UserAvatar $avatar): static
{
if ($this->avatars->removeElement($avatar)) {
// set the owning side to null (unless already changed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getEmail(): ?string
return $this->email;
}

public function setEmail(string $email): self
public function setEmail(string $email): static
{
$this->email = $email;

Expand Down Expand Up @@ -65,7 +65,7 @@ public function getRoles(): array
return array_unique($roles);
}

public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
$this->roles = $roles;

Expand All @@ -80,7 +80,7 @@ public function getPassword(): string
return $this->password;
}

public function setPassword(string $password): self
public function setPassword(string $password): static
{
$this->password = $password;

Expand Down
6 changes: 3 additions & 3 deletions tests/Security/fixtures/expected/UserEntityWithPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getUserIdentifier(): string
return (string) $this->userIdentifier;
}

public function setUserIdentifier(string $userIdentifier): self
public function setUserIdentifier(string $userIdentifier): static
{
$this->userIdentifier = $userIdentifier;

Expand All @@ -60,7 +60,7 @@ public function getRoles(): array
return array_unique($roles);
}

public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
$this->roles = $roles;

Expand All @@ -75,7 +75,7 @@ public function getPassword(): string
return $this->password;
}

public function setPassword(string $password): self
public function setPassword(string $password): static
{
$this->password = $password;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getUserIdentifier(): string
return (string) $this->user_identifier;
}

public function setUserIdentifier(string $user_identifier): self
public function setUserIdentifier(string $user_identifier): static
{
$this->user_identifier = $user_identifier;

Expand All @@ -60,7 +60,7 @@ public function getRoles(): array
return array_unique($roles);
}

public function setRoles(array $roles): self
public function setRoles(array $roles): static
{
$this->roles = $roles;

Expand All @@ -75,7 +75,7 @@ public function getPassword(): string
return $this->password;
}

public function setPassword(string $password): self
public function setPassword(string $password): static
{
$this->password = $password;

Expand Down
Loading