-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Improve inference for InputFilterPluginManager::get()
#97
Changes from all commits
15e9e3d
774bb40
be8b829
be509ec
68627d4
765bebb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
use Laminas\Validator\ValidatorInterface; | ||
use Traversable; | ||
|
||
use function assert; | ||
use function class_exists; | ||
use function get_debug_type; | ||
use function gettype; | ||
|
@@ -317,6 +318,7 @@ public function createInputFilter($inputFilterSpecification) | |
} | ||
|
||
$inputFilter = $this->getInputFilterManager()->get($type); | ||
assert($inputFilter instanceof InputFilterInterface); // As opposed to InputInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we know it is not an InputInterface here? InputFilterManager allows both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this ought to be full check for input filter with meaningful exception, not just an assert since the method is user facing and there is no soft guard somewhere else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An exception here would be a BC break though wouldn't it? The assertion will blow up in tests, it verifies the intended type for static analysis, and otherwise is a no-op for users There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wouldn't be. It would just be a fatal error if method not implemented or kinda work with anything as long as object has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more of a usability concern really. Exception would allow to say it needs to be input filter and get_debug_type was returned for the requested type |
||
|
||
if ($inputFilter instanceof CollectionInputFilter) { | ||
$inputFilter->setFactory($this); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\InputFilter\StaticAnalysis; | ||
|
||
use Laminas\InputFilter\InputFilterInterface; | ||
use Laminas\InputFilter\InputFilterPluginManager; | ||
use Laminas\InputFilter\InputInterface; | ||
|
||
final class InputFilterPluginManagerType | ||
{ | ||
public function __construct(private InputFilterPluginManager $manager) | ||
{ | ||
} | ||
|
||
public function getWillReturnAnInputOrInputFilterGivenAString( | ||
string $anyString, | ||
): InputInterface|InputFilterInterface { | ||
return $this->manager->get($anyString); | ||
} | ||
|
||
public function getWithFQCNWillReturnTheObjectOfType(): InputFilterWithTemplatedValues | ||
{ | ||
return $this->manager->get(InputFilterWithTemplatedValues::class); | ||
} | ||
|
||
public function getInvalidFQCNReturnsFallbackType(): InputInterface|InputFilterInterface | ||
{ | ||
return $this->manager->get(self::class); | ||
} | ||
} |
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.
Why psalm complains about plugin manager get? Does it want simple typehinted return and conditional be in psalm-return?
Also what is the MethodSignatureMismatch just above that was previously baselined? Is it due to psr container aliasing shenanigans?
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.
To answer it: some inherited weirdness going on.
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 a lot of this will be solved with SMv4 when we can drop PSR container v1 and tighten up the templates and types in the plugin manager.