ChromeDriver   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 3
dl 0
loc 133
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getFileName() 0 19 4
A getUrl() 0 5 1
A getOutputFileName() 0 5 1
A getLinuxFileName() 0 9 2
A removeOldVersions() 0 7 2
A getOldFilePattern() 0 4 1
A getDriverPath() 0 11 2
A getExtractedName() 0 10 2
1
<?php
2
namespace Peridot\WebDriverManager\Binary;
3
4
use Peridot\WebDriverManager\Versions;
5
6
/**
7
 * ChromeDriver is used to resolve the Selenium Server driver for using the Chrome
8
 * web browser.
9
 *
10
 * @package Peridot\WebDriverManager\Binary
11
 */
12
class ChromeDriver extends CompressedBinary implements DriverInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     *
17
     * @return string
18
     */
19
    public function getName()
20
    {
21
        return 'chromedriver';
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @return string
28
     */
29
    public function getFileName()
30
    {
31
        $file = "chromedriver_";
32
        $system = $this->resolver->getSystem();
33
34
        if ($system->isMac()) {
35
            $file .= 'mac64';
36
        }
37
38
        if ($system->isWindows()) {
39
            $file .= "win32";
40
        }
41
42
        if ($system->isLinux()) {
43
            $file .= $this->getLinuxFileName();
44
        }
45
46
        return "$file.zip";
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @return string
53
     */
54
    public function getUrl()
55
    {
56
        $version = Versions::CHROMEDRIVER;
57
        return "http://chromedriver.storage.googleapis.com/$version/{$this->getFileName()}";
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     *
63
     * @return string
64
     */
65
    public function getOutputFileName()
66
    {
67
        $version = Versions::CHROMEDRIVER;
68
        return "chromedriver_$version.zip";
69
    }
70
71
    /**
72
     * Get the linux filename.
73
     *
74
     * @return string
75
     */
76
    public function getLinuxFileName()
77
    {
78
        $file = "linux32";
79
        $system = $this->resolver->getSystem();
80
        if ($system->is64Bit()) {
81
            $file = 'linux64';
82
        }
83
        return $file;
84
    }
85
86
    /**
87
     * Remove old versions of the binary.
88
     *
89
     * @param $directory
90
     * @return void
91
     */
92
    protected function removeOldVersions($directory)
93
    {
94
        $paths = glob("$directory/chromedriver*");
95
        foreach ($paths as $path) {
96
            unlink($path);
97
        }
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     *
103
     * @param string $directory
104
     * @return string
105
     */
106
    protected function getOldFilePattern($directory)
107
    {
108
        return $directory . '/' . str_replace(Versions::CHROMEDRIVER, '*', $this->getOutputFileName());
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     *
114
     * @param string $directory
115
     * @return string
116
     */
117
    public function getDriverPath($directory)
118
    {
119
        $file = "$directory/chromedriver";
120
        $system = $this->resolver->getSystem();
121
122
        if ($system->isWindows()) {
123
            $file .= '.exe';
124
        }
125
126
        return "webdriver.chrome.driver=$file";
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     *
132
     * @return string
133
     */
134
    public function getExtractedName()
135
    {
136
        $name = $this->getName();
137
        $system = $this->resolver->getSystem();
138
139
        if ($system->isWindows()) {
140
            $name .= '.exe';
141
        }
142
        return $name;
143
    }
144
}
145