Fix errors reported by PHPStan
This commit is contained in:
5
phpstan.neon
Normal file
5
phpstan.neon
Normal file
@@ -0,0 +1,5 @@
|
||||
parameters:
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
|
||||
ignoreErrors:
|
||||
- '/Cannot call method [a-zA-Z0-9]+\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface|null\./'
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace FriendsOfBehat\SymfonyExtension\Driver;
|
||||
|
||||
use Behat\Mink\Driver\BrowserKitDriver;
|
||||
use Symfony\Component\BrowserKit\Client;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
final class SymfonyDriver extends BrowserKitDriver
|
||||
@@ -15,6 +16,16 @@ final class SymfonyDriver extends BrowserKitDriver
|
||||
*/
|
||||
public function __construct(KernelInterface $kernel, string $baseUrl)
|
||||
{
|
||||
parent::__construct($kernel->getContainer()->get('test.client'), $baseUrl);
|
||||
$testClient = $kernel->getContainer()->get('test.client');
|
||||
|
||||
if (!$testClient instanceof Client) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Expected service "test.client" to be an instance of "%s", got "%s" instead.',
|
||||
Client::class,
|
||||
\is_object($testClient) ? \get_class($testClient) : \gettype($testClient)
|
||||
));
|
||||
}
|
||||
|
||||
parent::__construct($testClient, $baseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
final class SymfonyExtension implements Extension
|
||||
{
|
||||
@@ -162,9 +163,13 @@ final class SymfonyExtension implements Extension
|
||||
$config['debug'],
|
||||
]);
|
||||
$definition->addMethodCall('boot');
|
||||
$definition->setFile($this->getKernelFile($container->getParameter('paths.base'), $config['path']));
|
||||
$definition->setPublic(true);
|
||||
|
||||
$file = $this->getKernelFile($container->getParameter('paths.base'), $config['path']);
|
||||
if (null !== $file) {
|
||||
$definition->setFile($file);
|
||||
}
|
||||
|
||||
$container->setDefinition(self::KERNEL_ID, $definition);
|
||||
|
||||
$this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']);
|
||||
@@ -221,7 +226,7 @@ final class SymfonyExtension implements Extension
|
||||
*/
|
||||
private function loadKernelRebooter(ContainerBuilder $container): void
|
||||
{
|
||||
$definition = new Definition(KernelRebooter::class, [$container->get(self::KERNEL_ID)]);
|
||||
$definition = new Definition(KernelRebooter::class, [new Reference(self::KERNEL_ID)]);
|
||||
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG);
|
||||
|
||||
$container->setDefinition(self::KERNEL_ID . '.rebooter', $definition);
|
||||
@@ -234,21 +239,29 @@ final class SymfonyExtension implements Extension
|
||||
*/
|
||||
private function declareSymfonyContainers(ContainerBuilder $container): void
|
||||
{
|
||||
if (null !== $this->crossContainerProcessor) {
|
||||
$this->crossContainerProcessor->addContainerAccessor(
|
||||
'symfony',
|
||||
new KernelBasedContainerAccessor($container->get(self::KERNEL_ID))
|
||||
);
|
||||
if (null === $this->crossContainerProcessor) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->crossContainerProcessor->addContainerAccessor(
|
||||
'symfony_driver',
|
||||
new KernelBasedContainerAccessor($container->get(self::DRIVER_KERNEL_ID))
|
||||
);
|
||||
$containerAccessors = [
|
||||
'symfony' => self::KERNEL_ID,
|
||||
'symfony_driver' => self::DRIVER_KERNEL_ID,
|
||||
'symfony_shared' => self::SHARED_KERNEL_ID,
|
||||
];
|
||||
|
||||
$this->crossContainerProcessor->addContainerAccessor(
|
||||
'symfony_shared',
|
||||
new KernelBasedContainerAccessor($container->get(self::SHARED_KERNEL_ID))
|
||||
);
|
||||
foreach ($containerAccessors as $containerName => $kernelIdentifier) {
|
||||
$kernel = $container->get($kernelIdentifier);
|
||||
|
||||
if (!$kernel instanceof KernelInterface) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Expected service "%s" to be an instance of "%s", got "%s" instead.',
|
||||
$kernelIdentifier,
|
||||
KernelInterface::class,
|
||||
\is_object($kernel) ? \get_class($kernel) : \gettype($kernel)
|
||||
));
|
||||
}
|
||||
|
||||
$this->crossContainerProcessor->addContainerAccessor($containerName, new KernelBasedContainerAccessor($kernel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +282,7 @@ final class SymfonyExtension implements Extension
|
||||
*/
|
||||
private function registerSymfonyDriverFactory(ExtensionManager $extensionManager): void
|
||||
{
|
||||
/** @var MinkExtension $minkExtension */
|
||||
/** @var MinkExtension|null $minkExtension */
|
||||
$minkExtension = $extensionManager->getExtension('mink');
|
||||
if (null === $minkExtension) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user