The base extension class automatically creates a Configuration instance when a Configuration class exists in the namespace of the extension. But PHPStan obviously doesn't understand this behaviour and always assumes that getConfiguration() returns ConfigurationInterface|null meaning that the default pattern to get and parse the configuration reports an error.
I.e.:
namespace Foo;
class SomeExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
}
}
results in an error because processConfiguration() doesn't accept ConfigurationInterface|null. But when a Configuration class exists in the same namespace as the Extension class (so Foo\Extension) an instance of it is returned.
This DynamicReturnTypeExtension overrides the return type of Extension::getConfiguration() so it automatically narrows the return type in case getConfiguration() is not overriden and a Configuration class exists. So that in the given example getConfiguration() doesn't return ConfigurationInterface|null anymore but Foo\Configuration and there is no error on calling processConfiguration().
The base extension class automatically creates a Configuration instance when a Configuration class exists in the namespace of the extension. But PHPStan obviously doesn't understand this behaviour and always assumes that
getConfiguration()
returnsConfigurationInterface|null
meaning that the default pattern to get and parse the configuration reports an error.I.e.:
results in an error because
processConfiguration()
doesn't acceptConfigurationInterface|null
. But when aConfiguration
class exists in the same namespace as theExtension
class (soFoo\Extension
) an instance of it is returned.This
DynamicReturnTypeExtension
overrides the return type ofExtension::getConfiguration()
so it automatically narrows the return type in casegetConfiguration()
is not overriden and aConfiguration
class exists. So that in the given examplegetConfiguration()
doesn't returnConfigurationInterface|null
anymore butFoo\Configuration
and there is no error on callingprocessConfiguration()
.