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

Improve magic methods generation #6896

Merged
merged 2 commits into from
Dec 31, 2023

Conversation

junichi11
Copy link
Member

@junichi11 junichi11 commented Dec 31, 2023

Improve magic methods generation

Generate __toString() magic method with all fields #6783

Example:

class Person {
    public string $name;
    private int $age;
    protected string $phoneNumber;
    private string $emailAddress;
}

Result:

class Person {
    public string $name;
    private int $age;
    protected string $phoneNumber;
    private string $emailAddress;
    public function __toString(): string {
        return "Person[name=" . $this->name
                . ", age=" . $this->age
                . ", phoneNumber=" . $this->phoneNumber
                . ", emailAddress=" . $this->emailAddress
                . "]";
    }
}

nb-php-gh-6783

@junichi11 junichi11 added the PHP [ci] enable extra PHP tests (php/php.editor) label Dec 31, 2023
@junichi11 junichi11 added this to the NB21 milestone Dec 31, 2023
@junichi11 junichi11 linked an issue Dec 31, 2023 that may be closed by this pull request
@junichi11 junichi11 requested a review from tmysik December 31, 2023 02:10
Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!

@junichi11
Copy link
Member Author

@tmysik Thank you for your review! I'll fix them later :)

- Add `__debugInfo()`
- Add parameter and return types
- Add/Fix unit tests
- https://www.php.net/manual/en/language.oop5.magic.php
- apache#6783
- Add/Fix unit tests

Example:
```php
class Person {
    public string $name;
    private int $age;
    protected string $phoneNumber;
    private string $emailAddress;
}
```

Result:
```php
class Person {
    public string $name;
    private int $age;
    protected string $phoneNumber;
    private string $emailAddress;
    public function __toString(): string {
        return "Person[name=" . $this->name
                . ", age=" . $this->age
                . ", phoneNumber=" . $this->phoneNumber
                . ", emailAddress=" . $this->emailAddress
                . "]";
    }
}
```
@junichi11 junichi11 force-pushed the php-gh-6783-tostring-method branch from bbbdf48 to 73b894c Compare December 31, 2023 12:00
@junichi11 junichi11 merged commit e458d63 into apache:master Dec 31, 2023
@junichi11 junichi11 deleted the php-gh-6783-tostring-method branch December 31, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PHP] Generate __toString in a Plain Object class
2 participants