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

Use NamedArgumentConstructorAnnotation for annotations #2243

Closed
wants to merge 1 commit into from

Conversation

malarzm
Copy link
Member

@malarzm malarzm commented Nov 9, 2020

Brings doctrine/annotations#369 to the ODM, here's what can be done later: doctrine/orm#8266

Q A
Type feature
BC Break kind of but not really (see UPGRADE notes)
Fixed issues n/a

@malarzm malarzm added the Feature label Nov 9, 2020
@malarzm malarzm added this to the 2.2.0 milestone Nov 9, 2020
{
/** @var string */
public $name;

/** @var string */
public $type = 'string';
/** @var string|null */
Copy link
Member Author

Choose a reason for hiding this comment

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

|null comes from @Id

/** @var string|string[] */
public $value;

/** @var string|null */
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to fix all the wrong docblocks by the way


public function __construct(string $value)
{
$this->value = $value;
Copy link
Member Author

@malarzm malarzm Nov 9, 2020

Choose a reason for hiding this comment

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

Idea for a later PR (or commit): add validation to ctors

{
/** @var string|null */
public $db;

/** @var string|null */
/** @var array|string|null */
Copy link
Member Author

Choose a reason for hiding this comment

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

array is used for capped collection's config

public $notSaved = true;
public function __construct(
string $name = 'chunkSize',
string $type = 'int',
Copy link
Member Author

@malarzm malarzm Nov 9, 2020

Choose a reason for hiding this comment

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

Does it even make sense to allow overriding anything but $name here? Same goes for other File-related annotations

Copy link
Member

Choose a reason for hiding this comment

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

No: only the name can be configured, the rest is specified in the GridFS Specification.

@@ -35,7 +32,7 @@ final class ReferenceMany extends AbstractField
/** @var string|null */
public $defaultDiscriminatorValue;

/** @var string[]|null */
/** @var string|string[]|null */
Copy link
Member Author

Choose a reason for hiding this comment

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

turns out using string is also fine, it's converted to an array later while mapping field

@malarzm malarzm force-pushed the named-ctor-annotations branch from bbb2f29 to 45bfb60 Compare November 9, 2020 23:03
@malarzm malarzm requested a review from alcaeus November 9, 2020 23:04
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

As a general theme, I'd advocate to rename the $value arguments in constructors to something more meaningful. For example, in the AlsoLoad annotation, $value doesn't really tell me what this should be, especially with $name being the other field. This is especially true with these names being somewhat relevant to BC when people use named arguments.

*
* @Annotation
*/
final class Inheritance extends Annotation
Copy link
Member

Choose a reason for hiding this comment

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

Given that this class is final and never checked for, it should be safe to remove it. I'm sure there's someone out there using it, not realising that it didn't do anything.

/**
* Specifies a parent class that other documents may extend to inherit mapping
* information
*
* @Annotation
*/
final class MappedSuperclass extends AbstractDocument
final class MappedSuperclass extends AbstractDocument implements NamedArgumentConstructorAnnotation
{
/** @var string */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/** @var string */
/** @var string|null */

@malarzm
Copy link
Member Author

malarzm commented Jan 9, 2021

Getting back to the PR got me so long somebody opened doctrine/annotations#396 which actually is great :)

@alcaeus alcaeus removed this from the 2.2.0 milestone Jan 12, 2021
Base automatically changed from master to 2.3.x February 2, 2021 21:41
@IonBazan
Copy link
Member

@malarzm Since #2344 has been merged and contains similar changes, should we close this one or would you like to backport the @NamedArgumentConstructorAnnotation changes to 2.2.x?

@malarzm
Copy link
Member Author

malarzm commented Aug 16, 2021

Nah, let's close this one 👍

@malarzm malarzm closed this Aug 16, 2021
@malarzm malarzm deleted the named-ctor-annotations branch August 16, 2021 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants