Skip to content

Commit

Permalink
Refine types for InputFilterPluginManager::get and add additional S…
Browse files Browse the repository at this point in the history
…A test

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Jan 10, 2024
1 parent 68627d4 commit e7cc0a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
<code>get</code>
</MethodSignatureMustProvideReturnType>
<MixedInferredReturnType>
<code><![CDATA[($name is class-string<T> ? T : InputInterface|InputFilterInterface)]]></code>
<code><![CDATA[($name is class-string<InputInterface> ? T1 : ($name is class-string<InputFilterInterface> ? T2 : InputInterface|InputFilterInterface))]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code>parent::get($name, $options)</code>
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<directory name="test/StaticAnalysis" />
</errorLevel>
</UnusedClass>
<PossiblyUnusedMethod>
<errorLevel type="suppress">
<directory name="test/StaticAnalysis" />
</errorLevel>
</PossiblyUnusedMethod>
</issueHandlers>

<stubs>
Expand Down
9 changes: 6 additions & 3 deletions src/InputFilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@ public function validatePlugin($plugin)

/**
* @inheritDoc
* @template T of InputInterface|InputFilterInterface
* @param class-string<T>|string $name
* @return ($name is class-string<T> ? T : InputInterface|InputFilterInterface)
* phpcs:disable Generic.Files.LineLength.TooLong
* // Template constraint required or we get mixed added to output. Two templates because union does not work
* @template T1 of InputInterface
* @template T2 of InputFilterInterface
* @param class-string<T1>|class-string<T2>|string $name
* @return ($name is class-string<InputInterface> ? T1 : ($name is class-string<InputFilterInterface> ? T2 : InputInterface|InputFilterInterface))
*/
public function get($name, ?array $options = null)
{
Expand Down
5 changes: 5 additions & 0 deletions test/StaticAnalysis/InputFilterPluginManagerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public function getWithFQCNWillReturnTheObjectOfType(): InputFilterWithTemplated
{
return $this->manager->get(InputFilterWithTemplatedValues::class);
}

public function getInvalidFQCNReturnsFallbackType(): InputInterface|InputFilterInterface
{
return $this->manager->get(self::class);
}
}

0 comments on commit e7cc0a1

Please sign in to comment.