Skip to content

Fix some return type annotations #33007

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

Merged
merged 1 commit into from
Aug 7, 2019

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Aug 7, 2019

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

This PR fixed some incorrect return type declarations I discovered while working on #32993.

@@ -179,8 +179,6 @@ protected function describeContainerParameter($parameter, array $options = [])

/**
* Writes data as json.
*
* @return array|string
Copy link
Member Author

Choose a reason for hiding this comment

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

💡 This method does not return anything.

@@ -334,7 +334,7 @@ public function addNode(\DOMNode $node)
*
* @param int $position The position
*
* @return self
* @return static
Copy link
Member Author

Choose a reason for hiding this comment

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

💡 Most methods in this class return the result of createSubCrawler() which is already (correctly) annotated with @return static.

@derrabus derrabus force-pushed the bugfix/return-types branch from eab81e2 to d531326 Compare August 7, 2019 09:15
@derrabus
Copy link
Member Author

derrabus commented Aug 7, 2019

I can ignore the fabbot.io error, I assume. 😎

@derrabus derrabus force-pushed the bugfix/return-types branch from d531326 to 0a78dc0 Compare August 7, 2019 12:10
*/
private function load($key)
{
$path = $this->getPath($key);

return file_exists($path) ? file_get_contents($path) : false;
return file_exists($path) ? file_get_contents($path) : 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.

As suggested by @Tobion in #32993 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

file_get_contents can also return false that we should cast to null. this will otherwise break the type hints later

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we talking about the file behind $path being deleted between the file_exists() and the file_get_contents() call or are there other reasons why file_get_contents could return false in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

permissions, race conditions and more probably

Copy link
Member Author

Choose a reason for hiding this comment

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

So, something like that?

return file_exists($path) && false !== $contents = file_get_contents($path) ? $contents : null;

Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicolas-grekas
Copy link
Member

Thank you @derrabus.

@nicolas-grekas nicolas-grekas merged commit 0a78dc0 into symfony:3.4 Aug 7, 2019
nicolas-grekas added a commit that referenced this pull request Aug 7, 2019
This PR was merged into the 3.4 branch.

Discussion
----------

Fix some return type annotations

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

This PR fixed some incorrect return type declarations I discovered while working on #32993.

Commits
-------

0a78dc0 Fix some return type annotations.
@derrabus derrabus deleted the bugfix/return-types branch August 7, 2019 12:38
nicolas-grekas added a commit that referenced this pull request Aug 8, 2019
… conditions (derrabus)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] Resilience against file_get_contents() race conditions

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

This PR addresses #33007 (comment).

Commits
-------

5892837 Resilience against file_get_contents() race conditions.
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Aug 8, 2019
… conditions (derrabus)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] Resilience against file_get_contents() race conditions

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

This PR addresses symfony/symfony#33007 (comment).

Commits
-------

5892837 Resilience against file_get_contents() race conditions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants