-
Notifications
You must be signed in to change notification settings - Fork 236
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
Introduce annotation metadata #247
Conversation
*/ | ||
public function __construct( | ||
string $name, | ||
?array $type, |
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.
Later on ?array
will be replaced by proper Type
.
?array $type, | ||
bool $required = false, | ||
bool $default = false, | ||
?array $enum = null |
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.
Later on enum info will be merged into Type.
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.
Overall looking good, what's the likeliness of this introducing a BC break, and should it target 1.x?
Also: needs a performance check now that #248 is merged |
This branch (already rebased):
Master:
|
I wouldn't push it to 1.x at this state. It doesn't change public API (I reverted removal of @alcaeus WDYT? |
The bench for Is there any hot path that we can inspect, or adding utility API on the builder to reduce hops? |
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.
Initial feedback below. In general I'd appreciate it if we can enable phpcs in travis-ci build pipeline before moving along with this. I've created #252 to track this.
In general, there are two main things I would like to see changed:
assert
is used throughout for sanity checks. Since assertions can (and many times, are) turned off, I don't think this is feasible for checking input parameters. I believe it makes more sense to throw exceptions here.- The metadata builders are immutable. While I believe that metadata itself needs to be immutable, using the builder in
DocParser
feels cumbersome and would be drastically improved if they weren't immutable. See additional comment below.
) | ||
); | ||
|
||
assert(count($defaultProperties) <= 1); |
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.
I wouldn't use assert
here. To quote from the manual:
Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correctly if assertion checking is not activated.
I agree with that statement and would rather throw a subclass of InvalidArgumentException
instead of using assert
: while the code does not fail now if there is more than one default property, this can introduce issues that are difficult to debug at a later stage.
*/ | ||
public function getIterator() : Traversable | ||
{ | ||
yield from array_values($this->metadata); |
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.
Out of curiosity, why don't we return an iterator with keys?
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.
I don't have strong opinion but it feels redundant to getName() and would encourage using $name => $metadata
pattern.
As per #253 (comment), we've decided to not apply doctrine/coding-standard for now. @Majkl578 I've marked style comments in my review above as resolved, feel free to ignore that feedback unless it bothers you personally 😉 |
d681cf4
to
4ff7b4b
Compare
Addressed review comments from @alcaeus. Also did two more changes:
Metadata:
Master:
|
100% coverage in Metadata namespace. 😃 |
lib/Doctrine/Annotations/Metadata/Exception/InvalidAnnotationTarget.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Annotations/Metadata/Exception/InvalidAnnotationTarget.php
Outdated
Show resolved
Hide resolved
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.
Few comments below. A couple of general ideas:
- Do you want to allow constructing exceptions without usage of the factories or should the constructor be private?
- Since there are a lot of final classes, this becomes very dependent on our own classes without the option to properly customise anything. I think we should introduce interfaces for the builders (containing only the
build
method as everything else is an implementation detail) as well as an interface for the metadata classes (like you did withMetadataCollection
). That way we're not closing down the entire API to the point where people will have to fork it if they want to change a single thing.
lib/Doctrine/Annotations/Metadata/Exception/InvalidAnnotationTarget.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Annotations/Metadata/Exception/MetadataAlreadyExists.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Annotations/Metadata/Exception/MetadataDoesNotExist.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Annotations/Metadata/Exception/TooManyDefaultProperties.php
Outdated
Show resolved
Hide resolved
Right now we allow it in Migrations and ORM master. Probably not a big deal, note that proper exception structure is yet to be introduced (converting AnnotationException to interface etc.).
This is intentional. Most of the parts of Annotations should not be extended and those that could should be carefully considered. |
lib/Doctrine/Annotations/Metadata/Builder/PropertyMetadataBuilder.php
Outdated
Show resolved
Hide resolved
Co-Authored-By: Majkl578 <[email protected]>
Replace nested untyped metadata arrays structure inside DocParser by proper object metadata classes with builder.
This idea is somewhat inspired by #75 but this approach uses separate PropertyMetadata instead of plain untyped array as well as being more strictly typed.
Metadata will later be used by the new parser as well.
This is just an internals refactoring so it's not a BC break. No existing tests were touched.