Chrome::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WSW\BrowserAutomation\Driver;
6
7
use Facebook\WebDriver\Chrome\ChromeOptions;
8
use Facebook\WebDriver\Remote\DesiredCapabilities;
9
use Facebook\WebDriver\Remote\RemoteWebDriver;
10
use Facebook\WebDriver\WebDriverCapabilities;
11
12
/**
13
 * Class Chrome
14
 *
15
 * @package WSW\BrowserAutomation\Driver
16
 */
17
class Chrome implements DriverInterface
18
{
19
    /**
20
     * @var WebDriverCapabilities
21
     */
22
    private $capabilities;
23
24
    /**
25
     * @var string
26
     */
27
    private $dsn;
28
29
    /**
30
     * @var RemoteWebDriver
31
     */
32
    private $driver;
33
34
    /**
35
     * Create a new instance and automatically start the driver.
36
     *
37
     * @param string $dsn
38
     * @param array $arguments
39
     * @param RemoteWebDriver $driver
40
     */
41 3
    public function __construct(
42
        string $dsn = 'http://localhost:4444/wd/hub',
43
        array $arguments = [],
44
        RemoteWebDriver $driver = null
45
    ) {
46
47 3
        $this->dsn = $dsn;
48 3
        $capabilities = DesiredCapabilities::chrome();
49 3
        $options = (new ChromeOptions())->addArguments($arguments);
50 3
        $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
51 3
        $this->capabilities = $capabilities;
52 3
        $this->driver = $driver ?? RemoteWebDriver::create($this->dsn, $this->capabilities);
53 3
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 3
    public function getDriver(): RemoteWebDriver
59
    {
60 3
        return $this->driver;
61
    }
62
}
63