-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Refined ServiceManager factory, delegator and configuration types, to allow for easier introspection of mis-configuration at type level #98
Conversation
1905064
to
3dcb25c
Compare
3dcb25c
to
84a38b5
Compare
84a38b5
to
dea1a52
Compare
dea1a52
to
4b895e2
Compare
4b895e2
to
5543de7
Compare
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 think this is a GREAT addition! I've flagged a few nitpicks, which are primarily to close a few more Psalm errors as well as simplify some of the methods by promoting early returns.
Otherwise, 🚢
40222ff
to
1cf60f2
Compare
1cf60f2
to
69bc237
Compare
After some talks to @Ocramius, we are thinking about extracting the The dedicated patch would target v4.0 which does not have any ETA and which would require a huge amount of work in a majority of our components. Maybe this is something for the hacktoberfest? |
@@ -23,6 +23,7 @@ interface DelegatorFactoryInterface | |||
* A factory that creates delegates of a given service | |||
* | |||
* @param string $name | |||
* @psalm-param callable():mixed $callback | |||
* @param null|array $options | |||
* @return object |
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.
If this is supposed to return object
, then $callback
cannot return mixed
.
I feel like the DelegatorFactoryInterface
may benefit from a templated type, in future (not here, due to BC)
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.
Since ContainerInterface#get
can return mixed
, this actually has to be mixed
:-(
But yes, having a templated type would help for sure but until then, I've thought that mixed
would be fine until the return type is object 🤷🏼♂️
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, but the commented line is about @return object
(wrong)
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.
Not sure if I can follow.
Do you want me to change existing documentation that we end up having bc breaks? as of now, due to the lack of typing, callable factories can return mixed. When I enforce object
now, this will be pain probably. Thats why I think that might be a BC break but I am not 100% sure tho.
Or do you want me to open up the return value of the delegator to be mixed?
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 think I am fine with both as I don't have that much experience with adding psalm types on such a widely used component. As always, I trust your experience. :-)
This reduces the overall baseline by 140 errors. Some errors still have to be suppressed inline. Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
…e review Signed-off-by: Maximilian Bösing <[email protected]>
…thin a unit test Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
…`factories` config entries Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
…erface` Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
This will prevent introducing BC breaks while still provide a soft return type. Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
This will ensure the test does exactly what it supposed to do. Signed-off-by: Maximilian Bösing <[email protected]>
69bc237
to
b906701
Compare
@@ -66,6 +67,8 @@ public function __construct(array $config = []) | |||
unset($config[$key]); | |||
} | |||
} | |||
|
|||
/** @psalm-suppress ArgumentTypeCoercion */ |
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 coercion shouldn't apply anymore: merge()
has the correct types? 🤔
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.
ArrayUtils::merge
returns array
and thus, psalm loses track.
Not sure if something like this would help psalm to keep track:
/**
* @template TArray1 of array
* @template TArray2 of array
* @param TArray1 $a
* @param TArray2 $b
* @return TArray1&TArray2
*/
But this wont properly work for nested arrays (as they are here). There is absolutely no way but to trust that ArrayUtils::merge
will return the same types.
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.
Yes, but you are not calling ArrayUtils::merge()
, but rather $this->merge()
, which is well typed, and has its own suppressions
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'll leave this alone for now - I think it's not worth wasting effort on it after all the work you've already put in this, and it's in the internals anyway :)
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've added reportUnusedPsalmSuppress
in the config and thats not reported so something might still be odd :-/
@@ -23,6 +23,7 @@ interface DelegatorFactoryInterface | |||
* A factory that creates delegates of a given service | |||
* | |||
* @param string $name | |||
* @psalm-param callable():mixed $callback | |||
* @param null|array $options | |||
* @return object |
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, but the commented line is about @return object
(wrong)
Signed-off-by: Maximilian Bösing <[email protected]>
…eeded Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
e175bb9
to
883ff57
Compare
@@ -66,6 +67,8 @@ public function __construct(array $config = []) | |||
unset($config[$key]); | |||
} | |||
} | |||
|
|||
/** @psalm-suppress ArgumentTypeCoercion */ |
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'll leave this alone for now - I think it's not worth wasting effort on it after all the work you've already put in this, and it's in the internals anyway :)
@@ -20,16 +21,23 @@ | |||
use function get_class; | |||
|
|||
/** | |||
* @see ConfigInterface |
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 really like how you used @see
to import types that are otherwise elided by the CS tooling :D
Dismissing feedback after multiple iterations highlighted a massive improvement in type detail/edge cases :)
🚢 will also release ASAP - it's a huge improvement :) |
Description
This reduces the overall baseline by 140 errors. Some errors still have to be suppressed inline.