-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Modernize documentation code #10126
Modernize documentation code #10126
Conversation
greg0ire
commented
Oct 12, 2022
•
edited
Loading
edited
- migrate to attributes;
- add helpful phpdoc annotations;
- use typed properties;
- add type declarations.
🤔 should I be targeting 2.13.x? After all, there is not much reason to wait for this. |
private $firstComment; | ||
/** Unidirectional - Many-To-One */ | ||
#[ManyToOne(targetEntity: Comment::class)] | ||
private Comment $firstComment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private Comment $firstComment; | |
private Comment|null $firstComment = null; |
ManyToOne
relations are nullable by default.
I wouldn't wait with the 2.14.0 release too long either, so targeting 2.14.x is just fine imho. |
e4664b8
to
e762952
Compare
e762952
to
7cbdc4a
Compare
7cbdc4a
to
2ecfee9
Compare
I retargeted to 2.13.x so as not to have things to convert when merging up. |
2ecfee9
to
7486f2a
Compare
8535f95
to
45d53e4
Compare
b964d68
to
c1eef4a
Compare
c1eef4a
to
4eb9289
Compare
@derrabus please take another look 🙏 |
- migrate to attributes; - add helpful phpdoc annotations; - use typed properties; - add type declarations. Co-authored-by: Alexander M. Turek <me@derrabus.de>
66cba2c
to
794777b
Compare
I applied your suggestions and removed the property that was outside the constructor for that particular comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP 7.4 is nearly gone, but it still feels weird to have attributes as the primary configuration when PHP 7 is still supported in composer :-D
@@ -451,17 +449,15 @@ besides specifying the sequence's name: | |||
|
|||
.. configuration-block:: | |||
|
|||
.. code-block:: php | |||
.. code-block:: attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we have several formats here, shouldn't we keep the annotation code-block too ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better yeah, I'll try to find some time to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #10157
* @DiscriminatorMap({"cc" = "Test\Component\ConcreteComponent", | ||
"cd" = "Test\Decorator\ConcreteDecorator"}) | ||
*/ | ||
#[Entity] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite the fact that branch is already merged: I personally prefer multiple attributes in single '#[...]' looks a bit cleaner ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was like that before 🤷
|
||
public function addPropertyChangedListener(PropertyChangedListener $listener) | ||
|
||
private array $_listeners = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider sending a PR
@@ -32,11 +32,12 @@ upon insert: | |||
|
|||
class User | |||
{ | |||
const STATUS_DISABLED = 0; | |||
const STATUS_ENABLED = 1; | |||
private const STATUS_DISABLED = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If referring to 8.1, enum example can be used here :)
#[Id, Column(type: 'integer')] | ||
private int|null $id = null; | ||
#[Column(type: 'string')] | ||
private string $name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should provide a default value, otherwise: creating new entity and calling getName will return fatal - if getter is strict too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, you might have a constructor preventing this entirely.
* @Cache("NONSTRICT_READ_WRITE") | ||
*/ | ||
#[Entity] | ||
#[Cache(usage: 'NONSTRICT_READ_WRITE')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string can be a real constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
return $this->commentsRead; | ||
} | ||
|
||
public function setFirstComment(Comment $c) { | ||
/** @param Collection<int, Comment> $c */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍
private $comments; | ||
private int $id; | ||
|
||
/** @var Collection<int, Comment> */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here: key can be mixed as we don't know how people are adding to collection via add or set :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if they do, they should get a warning from PHPStan/Psalm thanks to this annotation, so I stand by it.
To anyone finding more stuff to say after the merge: please send PRs instead 🙏 |
#[DiscriminatorMap(['cc' => Component\ConcreteComponent::class, | ||
'cd' => Decorator\ConcreteDecorator::class])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See discussion here slevomat/coding-standard#1456