Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 23, 2020
1 parent fdf5bd6 commit 3ca17f1
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/Console/ChromeDriverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ class ChromeDriverCommand extends Command
protected $directory = __DIR__.'/../../bin/';

/**
* The default commands to detect the installed Chrome/Chromium version.
* The default commands to detect the installed Chrome / Chromium version.
*
* @var array
*/
protected $chromeCommands = [
protected $chromeVersionCommands = [
'linux' => [
'/usr/bin/google-chrome --version',
'/usr/bin/chromium-browser --version',
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function version()
$version = $this->argument('version');

if ($this->option('detect')) {
$version = $this->chromeVersion(OperatingSystem::id());
$version = $this->detectChromeVersion(OperatingSystem::id());
}

if (! $version) {
Expand Down Expand Up @@ -208,6 +208,33 @@ protected function latestVersion()
return trim(file_get_contents($this->latestVersionUrl, false, stream_context_create($streamOptions)));
}

/**
* Detect the installed Chrome / Chromium major version.
*
* @param string $os
* @return int|bool
*/
protected function detectChromeVersion($os)
{
foreach ($this->chromeVersionCommands[$os] as $command) {
$process = Process::fromShellCommandline($command);

$process->run();

preg_match('/(\d+)(\.\d+){3}/', $process->getOutput(), $matches);

if (! isset($matches[1])) {
continue;
}

return $matches[1];
}

$this->error('Chrome version could not be detected.');

return false;
}

/**
* Download the ChromeDriver archive.
*
Expand Down Expand Up @@ -288,31 +315,4 @@ protected function getUrl(string $url)

return file_get_contents($url, false, $streamContext);
}

/**
* Detect the installed Chrome/Chromium major version.
*
* @param string $os
* @return int|bool
*/
protected function chromeVersion($os)
{
foreach ($this->chromeCommands[$os] as $command) {
$process = Process::fromShellCommandline($command);

$process->run();

preg_match('/(\d+)(\.\d+){3}/', $process->getOutput(), $matches);

if (! isset($matches[1])) {
continue;
}

return $matches[1];
}

$this->error('Chrome version could not be detected.');

return false;
}
}

0 comments on commit 3ca17f1

Please sign in to comment.