GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Environment::hasXvfb()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
namespace SeleniumSetup;
3
4
use GuzzleHttp\Client;
5
use GuzzleHttp\Event\ProgressEvent;
6
use SeleniumSetup\Config\ConfigInterface;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Process\Process;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\Console\Output\BufferedOutput;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class Environment
14
{
15
    protected $config;
16
    protected $fileSystem;
17
    protected $env;
18
    protected $input;
19
    protected $output;
20
21
    const OS_WINDOWS = 'windows';
22
    const OS_LINUX = 'linux';
23
    const OS_MAC = 'mac';
24
    const OS_TYPE_64BIT = '64bit';
25
    const OS_TYPE_32BIT = '32bit';
26
27
    public function __construct(
28
        ConfigInterface $config,
29
        InputInterface $input,
30
        OutputInterface $output
31
    ) {
32
        $this->config = $config;
33
        $this->fileSystem = new FileSystem();
34
        $this->input = $input;
35
        $this->output = $output;
36
    }
37
38
    // @todo Move to public methods into SeleniumSetup\Environment.
39
    public function test()
40
    {
41
        // Pre-requisites.
42
        $canInstall = true;
43
        $writeln = [];
44
45
        // Start checking.
46
        $javaVersion = $this->getJavaVersion();
47
48
        if (empty($javaVersion)) {
49
            $writeln[] = '<error>[ ] Java is not installed.</error>';
50
            $canInstall = false;
51
        } else {
52
            $writeln[] = '<info>[x] Java is installed.</info>';
53
            if ($this->isJavaVersionDeprecated($javaVersion)) {
54
                $writeln[] = '<error>[ ] Your Java version needs to be >= 1.6</error>';
55
                $canInstall = false;
56
            } else {
57
                $writeln[] = '<info>[x] Your Java version ' . $javaVersion . ' seems up to date.</info>';
58
            }
59
        }
60
61
        if ($this->isPHPVersionDeprecated()) {
62
            $writeln[] = '<error>[ ] Your PHP version ' . $this->getPHPVersion() . ' should be >= 5.3</error>';
63
            $canInstall = false;
64
        } else {
65
            $writeln[] = '<info>[x] Your PHP version is ' . $this->getPHPVersion() . '</info>';
66
        }
67
68
        if (!$this->hasPHPCurlExtInstalled()) {
69
            $writeln[] = '<error>[ ] cURL extension for PHP is missing.</error>';
70
            $canInstall = false;
71
        } else {
72
            $writeln[] = '<info>[x] cURL ' . $this->getPHPCurlExtVersion() . ' extension is installed.</info>';
73
        }
74
75
        if (!$this->hasPHPOpenSSLExtInstalled()) {
76
            $writeln[] = '<error>[ ] OpenSSL extension for PHP is missing.</error>';
77
            $canInstall = false;
78
        } else {
79
            $writeln[] = '<info>[x] ' . $this->getPHPOpenSSLExtVersion() . ' extension is installed.</info>';
80
        }
81
82
        $this->output->writeln($writeln);
83
84
        return $canInstall;
85
    }
86
87
    // @todo Fine-tune the Windows and Mac detection if possible.
88
    public function getOsName()
89
    {
90
        if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
91
            return self::OS_WINDOWS;
92
        } else if (
93
            strpos(strtolower(PHP_OS), 'mac') !== false ||
94
            strpos(strtolower(PHP_OS), 'darwin') !== false
95
        ) {
96
            return self::OS_MAC;
97
        } else {
98
            // Assume Linux.
99
            return self::OS_LINUX;
100
        }
101
    }
102
103
    public function getOsVersion()
104
    {
105
        // TODO: Implement getOsVersion() method.
106
    }
107
108
    public function getOsType()
109
    {
110
        //$type = php_uname('m');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
111
        if (strlen(decbin(~0)) == 64) {
112
            return self::OS_TYPE_64BIT;
113
        } else {
114
            return self::OS_TYPE_32BIT;
115
        }
116
    }
117
118
    public function isWindows()
119
    {
120
        return $this->getOsName() == self::OS_WINDOWS;
121
    }
122
123
    public function isMac()
124
    {
125
        return $this->getOsName() == self::OS_MAC;
126
    }
127
128
    public function isLinux()
129
    {
130
        return $this->getOsName() == self::OS_LINUX;
131
    }
132
    
133
    public function isAdmin()
134
    {
135
        if ($this->isWindows()) {
136
            $cmd = 'NET SESSION';
137
            $lookForNegative = '^System error';
138
139
        } else {
140
            $cmd = 'sudo -n true';
141
            $lookForNegative = '^sudo\: a password is required';
142
        }
143
144
        $output = new BufferedOutput();
145
146
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
147
        $process->run(function($type, $line) use ($output) {
148
            $output->write($line);
149
        });
150
        
151
        return !(preg_match('/' . $lookForNegative . '/is', $output->fetch()));
152
    }
153
154
    public function getJavaVersion()
155
    {
156
        $cmd = 'java -version';
157
158
        $output = new BufferedOutput();
159
160
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
161
        $process->run(function($type, $line) use ($output) {
162
            $output->write($line);
163
        });
164
        
165
        preg_match('/version "([0-9._]+)"/', $output->fetch(), $javaVersionMatches);
166
        $javaVersion = isset($javaVersionMatches[1]) ? $javaVersionMatches[1] : null;
167
168
        return $javaVersion;
169
    }
170
171
    public function isJavaVersionDeprecated($javaVersion)
172
    {
173
        return version_compare($javaVersion, '1.6') < 0;
174
    }
175
176
    public function hasJavaCli()
177
    {
178
        // TODO: Implement hasJavaCli() method.
179
    }
180
181
    public function hasPHPInstalled()
182
    {
183
        // TODO: Implement hasPHPInstalled() method.
184
    }
185
186
    public function getPHPVersion()
187
    {
188
        return PHP_VERSION;
189
    }
190
191
    public function isPHPVersionDeprecated()
192
    {
193
        return version_compare($this->getPHPVersion(), '5.3') < 0;
194
    }
195
196
    public function canUseTheLatestPHPUnitVersion()
197
    {
198
        return version_compare($this->getPHPVersion(), '5.6') >= 0;
199
    }
200
201
    public function hasPHPCurlExtInstalled()
202
    {
203
        return function_exists('curl_version');
204
    }
205
206
    public function getPHPCurlExtVersion()
207
    {
208
        return curl_version()['version'];
209
    }
210
211
    public function hasPHPOpenSSLExtInstalled()
212
    {
213
        return extension_loaded('openssl');
214
    }
215
216
    public function getPHPOpenSSLExtVersion()
217
    {
218
        return OPENSSL_VERSION_TEXT;
219
    }
220
221
    // @todo Decide if this is still neded.
222
    public function hasCurlCli()
223
    {
224
        //$command = new GetCurlVersionCommand();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
225
        //$commandInput = new ArrayInput([]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
226
        //$commandOutput = new BufferedOutput();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
227
        //$returnCode = $command->run($commandInput, $commandOutput);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
228
229
        //return preg_match('/^curl ([0-9._]+)/', $commandOutput->fetch());
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
230
    }
231
    
232
    public function getEnvVar($varName)
233
    {
234
        return getenv($varName);
235
    }
236
    
237
    public function setEnvVar($varName, $varValue = '')
238
    {
239
        if ($varValue != '') {
240
            putenv($varName . '=' . $varValue);
241
        } else {
242
            putenv($varName);
243
        }
244
    }
245
246
    public function addPathToGlobalPath($path)
247
    {
248
        if ($this->isWindows()) {
249
            $separator = ';';
250
        } else {
251
            $separator = ':';
252
        }
253
254
        putenv('PATH=' . getenv('PATH') . $separator . $path);
255
        $this->output->writeln(sprintf('Added %s to global path.', $path));
256
    }
257
258
    public function download($from, $to)
259
    {
260
        $client = new Client();
261
        $client->setDefaultOption('verify', SeleniumSetup::$APP_ROOT_PATH . DIRECTORY_SEPARATOR . SeleniumSetup::SSL_CERT_FILENAME);
262
        $request = $client->createRequest('GET', $from, ['save_to'=> $to]);
263
264
        $computeRemainingSize = function(ProgressEvent $e) {
265
            if ($e->downloaded <= 0) {
266
                return 0;
267
            }
268
            $remainingSize = $e->downloadSize - $e->downloaded;
269
            if ($remainingSize > 0) {
270
                return round($e->downloaded / $e->downloadSize, 2) * 100;
271
            } else {
272
                return 100;
273
            }
274
        };
275
276
        // $progress = new ProgressBar($output, 5);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
277
        // $progress->start();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
278
        $output = new BufferedOutput();
279
280
        $request->getEmitter()->on('progress', function(ProgressEvent $e) use ($computeRemainingSize, $output) {
281
282
            $output->write(
283
                sprintf("Downloaded %s%%\r", $computeRemainingSize($e))
284
            );
285
286
            //$a = $computeRemainingSize($e);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
287
            //if ($a == 100) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
288
            //    $progress->finish();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
289
            //} else {
290
            //    if ($a % 10 == 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
291
            //        $progress->advance();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
292
            //    }
293
            //}
294
        });
295
296
        $client->send($request);
297
298
        return $output->fetch();
299
    }
300
301
    public function getCurlVersion()
302
    {
303
        $cmd = 'curl -V';
304
305
        $output = $this->output;
306
307
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
308
        $process->run(function($type, $line) use ($output) {
309
            $output->write($line);
310
        });
311
    }
312
    
313 View Code Duplication
    public function killProcessByPid($pid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
314
    {
315
        if ($this->isWindows()) {
316
            $cmd = 'taskkill /F /PID %d';
317
        } else {
318
            $cmd = 'kill -9 %d';
319
        }
320
321
        $cmd = sprintf($cmd, $pid);
322
323
        $output = $this->output;
324
325
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
326
        $process->run(function($type, $line) use ($output) {
327
            $output->write($line);
328
        });
329
    }
330
331 View Code Duplication
    public function killProcessByName($processName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
332
    {
333
        if ($this->isWindows()) {
334
            $cmd = 'taskkill /F /IM %s';
335
        } else {
336
            $cmd = 'pgrep -f "%s" | xargs kill';
337
        }
338
339
        $cmd = sprintf($cmd, $processName);
340
341
        $output = $this->output;
342
343
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
344
        $process->run(function($type, $line) use ($output) {
345
            $output->write($line);
346
        });
347
    }
348
349 View Code Duplication
    public function listenToPort($port)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
350
    {
351
        if ($this->isWindows()) {
352
            $cmd = 'netstat -ano|findstr :%d';
353
        } else {
354
            $cmd = 'netstat -tulpn | grep :%d';
355
        }
356
357
        $cmd = sprintf($cmd, $port);
358
359
        $output = new BufferedOutput();
360
361
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
362
        $process->run(function($type, $line) use ($output) {
363
            $output->write($line);
364
        });
365
        
366
        return $output->fetch();
367
        
368
    }
369
    
370
    public function getPidFromListeningToPort($port)
371
    {
372
        $listenToPort = $this->listenToPort($port);
373
        if (!empty($listenToPort)) {
374
            if ($this->isWindows()) {
375
                preg_match('/LISTENING[\s]+([0-9]+)/is', $listenToPort, $matches);
376
            } else {
377
                preg_match('/LISTEN[\s]+([0-9]+)/is', $listenToPort, $matches);
378
            }
379
            return isset($matches[1]) ? $matches[1] : null;
380
        }
381
        return null;
382
    }
383
384
    public function makeExecutable($file)
385
    {
386
        if ($this->isWindows()) {
387
            $cmd = null;
388
        } else {
389
            $cmd = 'chmod +x %s';
390
        }
391
392
        if (!is_null($cmd)) {
393
            $output = $this->output;
394
395
            $cmd = sprintf($cmd, $file);
396
            $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
397
            $process->run(function($type, $line) use ($output) {
398
                $output->write($line);
399
            });
400
        }
401
    }
402
403
    public function startSeleniumProcess()
404
    {
405
        // @todo Refactor this in 5.0; split binaries and drivers; Add Opera.
406
        // @see https://github.com/bogdananton/Selenium-Setup/issues/12
407
        $cmdExtra = '';
408 View Code Duplication
        if ($binary = $this->config->getBinary('chromedriver.' . $this->getOsName() . '.' . $this->getOsType())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
409
            $cmdExtra .= sprintf(' -Dwebdriver.chrome.driver=%s', $this->config->getBuildPath() . DIRECTORY_SEPARATOR . $binary->getBinName());
410
        }
411 View Code Duplication
        if ($binary = $this->config->getBinary('iedriver.' . $this->getOsName() . '.' . $this->getOsType())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
412
            $cmdExtra .= sprintf(' -Dwebdriver.ie.driver=%s', $this->config->getBuildPath() . DIRECTORY_SEPARATOR . $binary->getBinName());
413
        }
414 View Code Duplication
        if ($binary = $this->config->getBinary('phantomjs.' . $this->getOsName() . '.' . $this->getOsType())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
415
            $cmdExtra .= sprintf(' -Dphantomjs.binary.path=%s', $this->config->getBuildPath() . DIRECTORY_SEPARATOR . $binary->getBinName());
416
        }
417
        
418
        if ($this->isWindows()) {
419
            $cmd = 'start /b java -jar %s -port %s -Dhttp.proxyHost=%s -Dhttp.proxyPort=%s -log %s %s';
420
        } else {
421
            $cmd = 'java -jar %s -port %s -Dhttp.proxyHost=%s -Dhttp.proxyPort=%s -log %s %s >/dev/null 2>&1 &';
422
423
        }
424
425
        $cmd = vsprintf($cmd, [
426
            'binary' => $this->config->getBuildPath() . DIRECTORY_SEPARATOR . $this->config->getBinary('selenium')->getBinName(),
427
            'port' => $this->config->getPort(),
428
            'proxyHost' => $this->config->getProxyHost(),
429
            'proxyPort' => $this->config->getProxyPort(),
430
            'log' => $this->config->getLogsPath() . DIRECTORY_SEPARATOR . 'selenium.log',
431
            'cmdExtra' => $cmdExtra
432
        ]);
433
434
        //var_dump($cmd);
435
436
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
437
        $process->start();
438
        // $process->getOutput();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
439
        return $process->getPid();
440
    }
441
    
442
    public function hasXvfb()
443
    {
444
        $cmd = 'which Xvfb';
445
        
446
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
447
        $process->start();
448
        return ($process->getOutput() != '' ? true : false);
449
    }
450
451
    public function startDisplayProcess()
452
    {
453
        if ($this->isWindows()) {
454
            $cmd = null;
455
        } else {
456
            if ($this->getEnvVar('DISPLAY')) {
457
                return true;
458
            }
459
            $this->setEnvVar('DISPLAY', ':99.0');
460
            $cmd = '/sbin/start-stop-daemon --start --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16';
461
        }
462
        $output = new BufferedOutput();
463
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
464
        $process->run(function($type, $line) use ($output) {
465
            $output->write($line);
466
        });
467
        //var_dump($process->getPid());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
468
        return $process->getPid();
469
    }
470
    
471 View Code Duplication
    public function getChromeVersion()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
472
    {
473
        if ($this->isWindows()) {
474
            $cmd = 'reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Google\Update\Clients\{8A69D345-D564-463c-AFF1-A69D9E530F96} | findstr /i pv';
475
            $match = '/REG_SZ[\s]+([0-9.]+)/is';
476
        } else {
477
            $cmd = 'google-chrome --version';
478
            $match = '/Google Chrome ([0-9.]+)/is';
479
        }
480
        
481
        $output = new BufferedOutput();
482
483
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
484
        $process->run(function($type, $line) use ($output) {
485
            $output->write($line);
486
        });
487
488
        preg_match($match, $output->fetch(), $matches);
489
490
        return isset($matches[1]) ? $matches[1] : null;
491
    }
492
    
493 View Code Duplication
    public function getFirefoxVersion()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
494
    {
495
        if ($this->isWindows()) {
496
            $cmd = 'reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox" | findstr /i CurrentVersion';
497
            $match = '/REG_SZ[\s]+([0-9.]+)/is';
498
        } else {
499
            $cmd = 'firefox --version';
500
            $match = '/Mozilla Firefox ([0-9.]+)/is';
501
        }
502
        $output = new BufferedOutput();
503
504
        $process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
505
        $process->run(function($type, $line) use ($output) {
506
            $output->write($line);
507
        });
508
509
        preg_match($match, $output->fetch(), $matches);
510
        
511
        return isset($matches[1]) ? $matches[1] : null;
512
    }
513
    
514
}
515