SymfonyDriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 26 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FriendsOfBehat\SymfonyExtension\Driver;
6
7
use Behat\Mink\Driver\BrowserKitDriver;
8
use Symfony\Component\BrowserKit\AbstractBrowser;
9
use Symfony\Component\BrowserKit\Client;
10
use Symfony\Component\HttpKernel\KernelInterface;
11
12
final class SymfonyDriver extends BrowserKitDriver
13
{
14
    public function __construct(KernelInterface $kernel, ?string $baseUrl)
15
    {
16
        if (!$kernel->getContainer()->has('test.client')) {
17
            throw new \RuntimeException(sprintf(
18
                'Kernel "%s" used by Behat with "%s" environment and debug %s does not have "test.client" service. ' . "\n" .
19
                'Please make sure the kernel is using "test" environment or have "framework.test" configuration option enabled.',
20
                get_class($kernel),
21
                $kernel->getEnvironment(),
22
                $kernel->isDebug() ? 'enabled' : 'disabled'
23
            ));
24
        }
25
26
        /** @var object $testClient */
27
        $testClient = $kernel->getContainer()->get('test.client');
28
29
        if (!$testClient instanceof Client && !$testClient instanceof AbstractBrowser) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\BrowserKit\Client does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
30
            throw new \RuntimeException(sprintf(
31
                'Service "test.client" should be an instance of "%s" or "%s", "%s" given.',
32
                Client::class,
33
                AbstractBrowser::class,
34
                get_class($testClient)
35
            ));
36
        }
37
38
        parent::__construct($testClient, $baseUrl);
39
    }
40
}
41