diff --git a/test/StaticAnalysis/CallablePluginManager.php b/test/StaticAnalysis/CallablePluginManager.php new file mode 100644 index 00000000..fdddacd1 --- /dev/null +++ b/test/StaticAnalysis/CallablePluginManager.php @@ -0,0 +1,51 @@ + + */ +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 + { + $this->validate($plugin); + return $plugin; + } + + 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.'); + } + } +} diff --git a/test/StaticAnalysis/ConcreteCallablePlugin.php b/test/StaticAnalysis/ConcreteCallablePlugin.php new file mode 100644 index 00000000..e14de0c8 --- /dev/null +++ b/test/StaticAnalysis/ConcreteCallablePlugin.php @@ -0,0 +1,13 @@ + + */ +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 + { + $this->validate($plugin); + return $plugin; + } + + 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.'); + } + } +}