-
Notifications
You must be signed in to change notification settings - Fork 185
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
Enhancement: Return types and general clean up #523
Enhancement: Return types and general clean up #523
Conversation
.php_cs
Outdated
@@ -15,6 +15,7 @@ $config = PhpCsFixer\Config::create() | |||
'no_unused_imports' => true, | |||
'ordered_imports' => true, | |||
'psr0' => false, | |||
'single_blank_line_before_namespace' => true, |
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.
What do you think about enabling this fixer in a separate PR (similar to - for example - #524)?
Personally, I like to do this in two steps:
- enable the fixer and commit (see the build fail)
- run
make cs
and commit (make the build pass)
A side effect of this is that I wait with enabling a fixer until I see a PR opened that indicates that a project could benefit from enabling a specific rule (for example, I spotted here that - while consistent in context of this PR - spacing is applied before :
in return type declarations, but both the proposed PSR-12 as well as the default configuration for the return_type_declaration
fixer indicate that no space should be used, so it's a good case for enabling the fixer on an existing project). 🤓
@@ -63,7 +63,7 @@ public function findProfile() | |||
* @return Talk | |||
* @throws NotAuthorizedException | |||
*/ | |||
public function getTalk($talkId) | |||
public function getTalk(int $talkId) |
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'm not entirely sure whether we have filtering in place that sorts out passing in a possibly integerish string
value via the UI, which if we didn't would fail with a TypeError
. What do you think, do we need to add missing tests here?
Also, what do think about adding/updating the corresponding @param
s in the docblocks?
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 checked where this function is called, and its only used in one place (outside of automated tests), which is the talk view action. And there it gets filtered to an int anyways.
So if we would call this from another place in the future it should enforce some validation as well.
classes/Domain/Model/Airport.php
Outdated
@@ -15,7 +15,7 @@ class Airport extends Eloquent implements AirportInformationDatabase | |||
* @return Airport |
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.
Should we update docblocks here and in other places as well?
I would like to refer to zendframework/zend-diactoros#37 (comment).
What do you think, @BackEndTea?
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.
Yeah i'll get around to updating that.
I guess this is also a time to wonder how much the docblocks are needed, if we can paint the whole picture with type declarations.
classes/Domain/Model/TalkComment.php
Outdated
@@ -1,6 +1,5 @@ | |||
<?php | |||
|
|||
|
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.
Looks like we definitely have a good case for enabling the single_blank_line_before_namespace
fixer!
👍
classes/Util/Immutable.php
Outdated
|
||
use Exception; | ||
|
||
trait Immutable |
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.
What do you think about cherry-picking cf62549 and consequently removing
Immutable
ImmutableObject
- both of which are in fact unused - as well as
ImmutableTest
in a separate PR?
While I think all of the changes proposed in this PR here are good, I tend to prefer smaller PRs addressing single issues, as they are easier to review (and thus make it faster into master
). Hope you don't mind me expressing this concern.
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.
Have to admit i had to figure out how to cherry pick a commit, but this is now done in #528
This needs a good rebase after all of your other outstanding PRs have been merged!
then
|
@localheinz I'll get to that once @chartjes has finished most PR's. |
Added return types and type declarations where possible in Speakers
Removed double whitespace before the namespace which doesn't get picked up by phpcs, and added return types
- Added whitespace between <?php and the namespace for consistency - Added return types to Form functions - Removed useless comments
This rule has already been applied just about everywhere in the code base, so it might be better to enforce it for consistency.
This function is used in exactly one place, the view action of the talk controller, where the talk id is filtered to an int. So we should be okay to force this as an int.
This PR adds return types to a lot of functions. Functions that could also return null/ other types of responses haven't been updated.
It also forces some types on parameters where possible. And updates some docblocks