Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
cretueusebiu authored and StyleCIBot committed Dec 30, 2016
1 parent a3df8ff commit 7308477
Show file tree
Hide file tree
Showing 43 changed files with 763 additions and 635 deletions.
38 changes: 19 additions & 19 deletions cli/Valet/Acrylic.php
Expand Up @@ -2,27 +2,26 @@

namespace Valet;

use Exception;
use DomainException;

class Acrylic
{
var $cli, $files;
public $cli;
public $files;

/**
* Create a new Acrylic instance.
*
* @param CommandLine $cli
* @param Filesystem $files
* @param CommandLine $cli
* @param Filesystem $files
*
* @return void
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
}

function install($domain = 'dev')
public function install($domain = 'dev')
{
$this->cli->runOrDie('cmd "/C '.$this->path().'/AcrylicController InstallAcrylicService"', function ($code, $output) {
warning($output);
Expand All @@ -33,7 +32,7 @@ function install($domain = 'dev')
$this->restart();
}

function createConfigFile($domain)
public function createConfigFile($domain)
{
$contents = $this->files->get(__DIR__.'/../stubs/AcrylicHosts.txt');

Expand All @@ -44,19 +43,20 @@ function createConfigFile($domain)

$customConfigPath = VALET_HOME_PATH.'/AcrylicHosts.txt';

if (! $this->files->exists($customConfigPath)) {
if (!$this->files->exists($customConfigPath)) {
$this->files->putAsUser($customConfigPath, PHP_EOL);
}
}

/**
* Update the domain used by Acrylic DNS.
*
* @param string $oldDomain
* @param string $newDomain
* @param string $oldDomain
* @param string $newDomain
*
* @return void
*/
function updateDomain($oldDomain, $newDomain)
public function updateDomain($oldDomain, $newDomain)
{
$this->stop();

Expand All @@ -65,14 +65,14 @@ function updateDomain($oldDomain, $newDomain)
$this->restart();
}

function uninstall()
public function uninstall()
{
$this->stop();

$this->cli->quietly('cmd "/C '.$this->path().'/AcrylicController UninstallAcrylicService"');
}

function start()
public function start()
{
$this->cli->runOrDie('cmd "/C '.$this->path().'/AcrylicController StartAcrylicServiceSilently"', function ($code, $output) {
warning($output);
Expand All @@ -81,21 +81,21 @@ function start()
$this->flushdns();
}

function stop()
public function stop()
{
$this->cli->run('cmd "/C '.$this->path().'/AcrylicController StopAcrylicServiceSilently"');

$this->flushdns();
}

function restart()
public function restart()
{
$this->stop();

$this->start();
}

function flushdns()
public function flushdns()
{
$this->cli->run('cmd "/C ipconfig /flushdns"');
}
Expand All @@ -105,7 +105,7 @@ function flushdns()
*
* @return string
*/
function path()
public function path()
{
return realpath(__DIR__.'/../../bin/Acrylic/');
}
Expand Down
60 changes: 33 additions & 27 deletions cli/Valet/Brew.php
Expand Up @@ -2,21 +2,23 @@

namespace Valet;

use Exception;
use DomainException;
use Exception;

class Brew
{
var $cli, $files;
public $cli;
public $files;

/**
* Create a new Brew instance.
*
* @param CommandLine $cli
* @param Filesystem $files
* @param CommandLine $cli
* @param Filesystem $files
*
* @return void
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
Expand All @@ -25,10 +27,11 @@ function __construct(CommandLine $cli, Filesystem $files)
/**
* Determine if the given formula is installed.
*
* @param string $formula
* @param string $formula
*
* @return bool
*/
function installed($formula)
public function installed($formula)
{
return in_array($formula, explode(PHP_EOL, $this->cli->runAsUser('brew list | grep '.$formula)));
}
Expand All @@ -38,7 +41,7 @@ function installed($formula)
*
* @return bool
*/
function hasInstalledPhp()
public function hasInstalledPhp()
{
return $this->installed('php71')
|| $this->installed('php70')
Expand All @@ -49,27 +52,29 @@ function hasInstalledPhp()
/**
* Ensure that the given formula is installed.
*
* @param string $formula
* @param array $options
* @param array $taps
* @param string $formula
* @param array $options
* @param array $taps
*
* @return void
*/
function ensureInstalled($formula, $options = [], $taps = [])
public function ensureInstalled($formula, $options = [], $taps = [])
{
if (! $this->installed($formula)) {
if (!$this->installed($formula)) {
$this->installOrFail($formula, $options, $taps);
}
}

/**
* Install the given formula and throw an exception on failure.
*
* @param string $formula
* @param array $options
* @param array $taps
* @param string $formula
* @param array $options
* @param array $taps
*
* @return void
*/
function installOrFail($formula, $options = [], $taps = [])
public function installOrFail($formula, $options = [], $taps = [])
{
if (count($taps) > 0) {
$this->tap($taps);
Expand All @@ -87,10 +92,11 @@ function installOrFail($formula, $options = [], $taps = [])
/**
* Tap the given formulas.
*
* @param dynamic[string] $formula
* @param dynamic[string] $formula
*
* @return void
*/
function tap($formulas)
public function tap($formulas)
{
$formulas = is_array($formulas) ? $formulas : func_get_args();

Expand All @@ -104,7 +110,7 @@ function tap($formulas)
*
* @param
*/
function restartService($services)
public function restartService($services)
{
$services = is_array($services) ? $services : func_get_args();

Expand All @@ -118,7 +124,7 @@ function restartService($services)
*
* @param
*/
function stopService($services)
public function stopService($services)
{
$services = is_array($services) ? $services : func_get_args();

Expand All @@ -132,10 +138,10 @@ function stopService($services)
*
* @return string
*/
function linkedPhp()
public function linkedPhp()
{
if (! $this->files->isLink('/usr/local/bin/php')) {
throw new DomainException("Unable to determine linked PHP.");
if (!$this->files->isLink('/usr/local/bin/php')) {
throw new DomainException('Unable to determine linked PHP.');
}

$resolvedPath = $this->files->readLink('/usr/local/bin/php');
Expand All @@ -149,7 +155,7 @@ function linkedPhp()
} elseif (strpos($resolvedPath, 'php55') !== false) {
return 'php55';
} else {
throw new DomainException("Unable to determine linked PHP.");
throw new DomainException('Unable to determine linked PHP.');
}
}

Expand All @@ -158,7 +164,7 @@ function linkedPhp()
*
* @return void
*/
function restartLinkedPhp()
public function restartLinkedPhp()
{
$this->restartService($this->linkedPhp());
}
Expand All @@ -168,7 +174,7 @@ function restartLinkedPhp()
*
* @return void
*/
function createSudoersEntry()
public function createSudoersEntry()
{
$this->files->ensureDirExists('/etc/sudoers.d');

Expand Down
46 changes: 27 additions & 19 deletions cli/Valet/CommandLine.php
Expand Up @@ -9,56 +9,61 @@ class CommandLine
/**
* Simple global function to run commands.
*
* @param string $command
* @param string $command
*
* @return void
*/
function quietly($command)
public function quietly($command)
{
$this->runCommand($command.' > /dev/null 2>&1');
}

/**
* Simple global function to run commands.
*
* @param string $command
* @param string $command
*
* @return void
*/
function quietlyAsUser($command)
public function quietlyAsUser($command)
{
$this->quietly('sudo -u '.user().' '.$command.' > /dev/null 2>&1');
}

/**
* Pass the command to the command line and display the output.
*
* @param string $command
* @param string $command
*
* @return void
*/
function passthru($command)
public function passthru($command)
{
passthru($command);
}

/**
* Run the given command as the non-root user.
*
* @param string $command
* @param callable $onError
* @param string $command
* @param callable $onError
*
* @return string
*/
function run($command, callable $onError = null)
public function run($command, callable $onError = null)
{
return $this->runCommand($command, $onError);
}

/**
* Run the given command and die if fails.
*
* @param string $command
* @param callable $onError
* @param string $command
* @param callable $onError
*
* @return string
*/
function runOrDie($command, callable $onError = null)
public function runOrDie($command, callable $onError = null)
{
return $this->run($command, function ($code, $output) use ($onError) {
if ($onError) {
Expand All @@ -72,25 +77,28 @@ function runOrDie($command, callable $onError = null)
/**
* Run the given command.
*
* @param string $command
* @param callable $onError
* @param string $command
* @param callable $onError
*
* @return string
*/
function runAsUser($command, callable $onError = null)
public function runAsUser($command, callable $onError = null)
{
return $this->runCommand('sudo -u '.user().' '.$command, $onError);
}

/**
* Run the given command.
*
* @param string $command
* @param callable $onError
* @param string $command
* @param callable $onError
*
* @return string
*/
function runCommand($command, callable $onError = null)
public function runCommand($command, callable $onError = null)
{
$onError = $onError ?: function () {};
$onError = $onError ?: function () {
};

$process = new Process($command);

Expand Down

0 comments on commit 7308477

Please sign in to comment.