-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qa: add some more static analysis files regarding plugin managers
Signed-off-by: Maximilian Bösing <[email protected]>
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\ServiceManager\StaticAnalysis; | ||
|
||
use Laminas\ServiceManager\AbstractPluginManager; | ||
use Laminas\ServiceManager\Exception\InvalidArgumentException; | ||
|
||
use function is_callable; | ||
|
||
/** | ||
* @template-extends AbstractPluginManager<callable> | ||
*/ | ||
final class CallablePluginManager extends AbstractPluginManager | ||
{ | ||
public function getWhateverPlugin(array|null $options = null): callable | ||
{ | ||
if ($options === null) { | ||
return $this->get('foo'); | ||
} | ||
|
||
return $this->build('foo', $options); | ||
} | ||
|
||
public function validateWhateverPlugin(mixed $plugin): callable | ||
Check failure on line 26 in test/StaticAnalysis/CallablePluginManager.php GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...MixedReturnTypeCoercion
|
||
{ | ||
$this->validate($plugin); | ||
return $plugin; | ||
Check failure on line 29 in test/StaticAnalysis/CallablePluginManager.php GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...MixedReturnTypeCoercion
|
||
} | ||
|
||
public function getConcretePlugin(): ConcreteCallablePlugin | ||
{ | ||
return self::get(ConcreteCallablePlugin::class); | ||
} | ||
|
||
public function buildConcretePlugin(): ConcreteCallablePlugin | ||
{ | ||
return self::build(ConcreteCallablePlugin::class); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function validate(mixed $instance): void | ||
{ | ||
if (! is_callable($instance)) { | ||
throw new InvalidArgumentException('Provided instance is not callable.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\ServiceManager\StaticAnalysis; | ||
|
||
final class ConcreteCallablePlugin | ||
{ | ||
public function __invoke(): mixed | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\ServiceManager\StaticAnalysis; | ||
|
||
use Laminas\ServiceManager\AbstractPluginManager; | ||
use Laminas\ServiceManager\Exception\InvalidArgumentException; | ||
|
||
use function is_callable; | ||
|
||
/** | ||
* `laminas-view` HelperPluginManager is providing either an object or a callable and thus needs to provide a union | ||
* return type. | ||
* | ||
* @psalm-type CallableObjectType = object&callable | ||
* @template-extends AbstractPluginManager<callable|CallableObjectType> | ||
*/ | ||
final class UnionPluginManager extends AbstractPluginManager | ||
{ | ||
/** | ||
* @return callable|CallableObjectType | ||
*/ | ||
public function getWhateverPlugin(array|null $options = null): callable|object | ||
{ | ||
if ($options === null) { | ||
return $this->get('foo'); | ||
} | ||
|
||
return $this->build('foo', $options); | ||
} | ||
|
||
public function validateWhateverPlugin(mixed $plugin): callable|object | ||
Check failure on line 33 in test/StaticAnalysis/UnionPluginManager.php GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...MixedReturnTypeCoercion
|
||
{ | ||
$this->validate($plugin); | ||
return $plugin; | ||
Check failure on line 36 in test/StaticAnalysis/UnionPluginManager.php GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...MixedReturnTypeCoercion
|
||
} | ||
|
||
public function getConcretePlugin(): ConcreteCallablePlugin | ||
{ | ||
return self::get(ConcreteCallablePlugin::class); | ||
} | ||
|
||
public function buildConcretePlugin(): ConcreteCallablePlugin | ||
{ | ||
return self::build(ConcreteCallablePlugin::class); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function validate(mixed $instance): void | ||
{ | ||
if (! is_callable($instance)) { | ||
throw new InvalidArgumentException('Provided instance is not callable.'); | ||
} | ||
} | ||
} |