-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Conversation
@@ -179,8 +179,6 @@ protected function describeContainerParameter($parameter, array $options = []) | |||
|
|||
/** | |||
* Writes data as json. | |||
* | |||
* @return array|string |
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 method does not return anything.
@@ -334,7 +334,7 @@ public function addNode(\DOMNode $node) | |||
* | |||
* @param int $position The position | |||
* | |||
* @return self | |||
* @return static |
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.
💡 Most methods in this class return the result of createSubCrawler()
which is already (correctly) annotated with @return static
.
eab81e2
to
d531326
Compare
I can ignore the fabbot.io error, I assume. 😎 |
d531326
to
0a78dc0
Compare
*/ | ||
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; |
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 suggested by @Tobion in #32993 (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.
file_get_contents can also return false that we should cast to null. this will otherwise break the type hints later
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.
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?
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.
permissions, race conditions and more probably
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.
So, something like that?
return file_exists($path) && false !== $contents = file_get_contents($path) ? $contents : 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.
lgtm
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.
Thank you @derrabus. |
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.
… 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.
… 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.
This PR fixed some incorrect return type declarations I discovered while working on #32993.