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 table and column comments non-nullable strings #3949

Merged
merged 1 commit into from
Apr 14, 2020

Conversation

morozov
Copy link
Member

@morozov morozov commented Apr 13, 2020

Q A
Type improvement
BC Break yes
  1. The $comment arguments were marked as nullable during the scalar types enforcement in the codebase (Enforced parameter and return value types in Platform classes #3562, Added type hints to the Column class #3511) because, despite the fact they were annotated as string in phpDoc, the values might contain NULL at runtime.
  2. In practice a NULL comment and an empty comment are indistinguishable (there either is a comment or there's no).
  3. Although the underlying platforms support nullable comments (except for SQLite), they are impossible to implement for commented types that store their type on the comment.
  4. The codebase currently contains expressions like (string) $comment or if ($comment === null || $comment === '') which illustrates that there's no practical difference between them at the abstraction level.
  5. The removed functional tests were removed in favor of the newly introduced ColumnCommentTest that is cross-platform and more focused on the API rather than on implementation details.

}

/**
* @return mixed[][]
Copy link
Member

Choose a reason for hiding this comment

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

Phpstan is ok with mixed[][], but Psalm isn't.

Suggested change
* @return mixed[][]
* @return iterable<mixed[]>

Copy link
Member Author

@morozov morozov Apr 14, 2020

Choose a reason for hiding this comment

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

As far as I understand, [] is a list/collection. It doesn't imply a specific implementation. It looks like Psalm thinks differently (cannot find a reference).

I'm fine to adjust but I'd rather do it for the entire codebase and have the rule enforced on CI. E.g. by adding a dependency on Psalm and setting the lowest possible level. Otherwise, it will become a matter of personal preference rather than a standard.

$ git grep 'mixed[][]' tests | wc -l
96

$ git grep 'iterable<mixed\[\]>' tests | wc -l
0

Copy link
Member

Choose a reason for hiding this comment

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

Ok let's not make this a blocker

}

/**
* @return mixed[][]
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
* @return mixed[][]
* @return iterable<mixed[]>

@morozov morozov merged commit 1eba78d into doctrine:master Apr 14, 2020
@morozov morozov deleted the non-nullable-comments branch April 14, 2020 16:42
@morozov morozov self-assigned this Apr 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants