Skip to content

Commit

Permalink
Merge pull request #18 from genesisweb/analysis-AD35Ay
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
dvmunjapara committed May 9, 2020
2 parents cb7c123 + 66da6c3 commit e237cbd
Show file tree
Hide file tree
Showing 68 changed files with 1,297 additions and 1,042 deletions.
24 changes: 13 additions & 11 deletions cli/Valet/CliPrompt.php
@@ -1,38 +1,40 @@
<?php


namespace Valet;


class CliPrompt
{

/**
* Prompts the user for input and shows what they type
* Prompts the user for input and shows what they type.
*
* @param $question
* @param bool $hidden
* @param null $suggestion
* @param null $default
*
* @return string
*/
public function prompt($question,$hidden = false,$suggestion = null,$default = null)
public function prompt($question, $hidden = false, $suggestion = null, $default = null)
{
$question = $suggestion? "$question [$suggestion]":$question;
$question = $default? "$question ($default)":$question;
$question = $suggestion ? "$question [$suggestion]" : $question;
$question = $default ? "$question ($default)" : $question;
$question .= PHP_EOL;

print_r($question);

if($hidden) system('stty -echo');
if ($hidden) {
system('stty -echo');
}
$answer = self::trimAnswer(fgets(STDIN, 4096));
if($hidden) system('stty echo');
if ($hidden) {
system('stty echo');
}

return !empty($answer)?$answer:$default;
return !empty($answer) ? $answer : $default;
}

private static function trimAnswer($str)
{
return preg_replace('{\r?\n$}D', '', $str);
}
}
}
24 changes: 15 additions & 9 deletions cli/Valet/CommandLine.php
Expand Up @@ -9,7 +9,8 @@ class CommandLine
/**
* Simple global function to run commands.
*
* @param string $command
* @param string $command
*
* @return void
*/
public function quietly($command)
Expand All @@ -20,7 +21,8 @@ public function quietly($command)
/**
* Simple global function to run commands.
*
* @param string $command
* @param string $command
*
* @return void
*/
public function quietlyAsUser($command)
Expand All @@ -31,7 +33,8 @@ public function quietlyAsUser($command)
/**
* Pass the command to the command line and display the output.
*
* @param string $command
* @param string $command
*
* @return void
*/
public function passthru($command)
Expand All @@ -42,8 +45,9 @@ public function 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
*/
public function run($command, callable $onError = null)
Expand All @@ -54,8 +58,9 @@ public function run($command, callable $onError = null)
/**
* Run the given command.
*
* @param string $command
* @param callable $onError
* @param string $command
* @param callable $onError
*
* @return string
*/
public function runAsUser($command, callable $onError = null)
Expand All @@ -66,8 +71,9 @@ public function runAsUser($command, callable $onError = null)
/**
* Run the given command.
*
* @param string $command
* @param callable $onError
* @param string $command
* @param callable $onError
*
* @return string
*/
protected function runCommand($command, callable $onError = null)
Expand Down
26 changes: 16 additions & 10 deletions cli/Valet/Configuration.php
Expand Up @@ -122,16 +122,17 @@ public function createCertificatesDirectory()
*/
public function writeBaseConfiguration()
{
if (! $this->files->exists($this->path())) {
if (!$this->files->exists($this->path())) {
$this->write(['domain' => 'test', 'paths' => [], 'port' => '80']);
}
}

/**
* Add the given path to the configuration.
*
* @param string $path
* @param bool $prepend
* @param string $path
* @param bool $prepend
*
* @return void
*/
public function addPath($path, $prepend = false)
Expand All @@ -146,7 +147,8 @@ public function addPath($path, $prepend = false)
/**
* Prepend the given path to the configuration.
*
* @param string $path
* @param string $path
*
* @return void
*/
public function prependPath($path)
Expand All @@ -157,7 +159,8 @@ public function prependPath($path)
/**
* Add the given path to the configuration.
*
* @param string $path
* @param string $path
*
* @return void
*/
public function removePath($path)
Expand All @@ -176,7 +179,7 @@ public function removePath($path)
*/
public function prune()
{
if (! $this->files->exists($this->path())) {
if (!$this->files->exists($this->path())) {
return;
}

Expand All @@ -201,7 +204,8 @@ public function read()
* Get a configuration value.
*
* @param string $key
* @param mixed $default
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default = null)
Expand All @@ -214,8 +218,9 @@ public function get($key, $default = null)
/**
* Update a specific key in the configuration file.
*
* @param string $key
* @param mixed $value
* @param string $key
* @param mixed $value
*
* @return array
*/
public function updateKey($key, $value)
Expand All @@ -229,7 +234,8 @@ public function updateKey($key, $value)
/**
* Write the given configuration to disk.
*
* @param array $config
* @param array $config
*
* @return void
*/
public function write(array $config)
Expand Down
9 changes: 6 additions & 3 deletions cli/Valet/Contracts/PackageManager.php
Expand Up @@ -7,23 +7,26 @@ interface PackageManager
/**
* Determine if the given package is installed.
*
* @param string $package
* @param string $package
*
* @return bool
*/
public function installed($package);

/**
* Ensure that the given package is installed.
*
* @param string $package
* @param string $package
*
* @return void
*/
public function ensureInstalled($package);

/**
* Install the given package and throw an exception on failure.
*
* @param string $package
* @param string $package
*
* @return void
*/
public function installOrFail($package);
Expand Down
6 changes: 6 additions & 0 deletions cli/Valet/Contracts/ServiceManager.php
Expand Up @@ -8,6 +8,7 @@ interface ServiceManager
* Start the given services.
*
* @param
*
* @return void
*/
public function start($services);
Expand All @@ -16,6 +17,7 @@ public function start($services);
* Stop the given services.
*
* @param
*
* @return void
*/
public function stop($services);
Expand All @@ -24,6 +26,7 @@ public function stop($services);
* Restart the given services.
*
* @param
*
* @return void
*/
public function restart($services);
Expand All @@ -32,6 +35,7 @@ public function restart($services);
* Enable the given services.
*
* @param
*
* @return bool
*/
public function enable($services);
Expand All @@ -40,6 +44,7 @@ public function enable($services);
* Disable the given services.
*
* @param
*
* @return bool
*/
public function disable($services);
Expand All @@ -48,6 +53,7 @@ public function disable($services);
* Status the given services.
*
* @param
*
* @return void
*/
public function status($services);
Expand Down
29 changes: 14 additions & 15 deletions cli/Valet/DnsMasq.php
Expand Up @@ -28,15 +28,15 @@ class DnsMasq
*/
public function __construct(PackageManager $pm, ServiceManager $sm, Filesystem $files, CommandLine $cli)
{
$this->pm = $pm;
$this->sm = $sm;
$this->cli = $cli;
$this->pm = $pm;
$this->sm = $sm;
$this->cli = $cli;
$this->files = $files;
$this->rclocal = '/etc/rc.local';
$this->resolvconf = '/etc/resolv.conf';
$this->dnsmasqconf = '/etc/dnsmasq.conf';
$this->configPath = '/etc/dnsmasq.d/valet';
$this->dnsmasqOpts = '/etc/dnsmasq.d/options';
$this->resolvconf = '/etc/resolv.conf';
$this->dnsmasqconf = '/etc/dnsmasq.conf';
$this->configPath = '/etc/dnsmasq.d/valet';
$this->dnsmasqOpts = '/etc/dnsmasq.d/options';
$this->nmConfigPath = '/etc/NetworkManager/conf.d/valet.conf';
$this->resolvedConfigPath = '/etc/systemd/resolved.conf';
}
Expand All @@ -52,7 +52,7 @@ private function _lockResolvConf($lock = true)
{
$arg = $lock ? '+i' : '-i';

if (! $this->files->isLink($this->resolvconf)) {
if (!$this->files->isLink($this->resolvconf)) {
$this->cli->run(
"chattr {$arg} {$this->resolvconf}",
function ($code, $msg) {
Expand All @@ -63,26 +63,26 @@ function ($code, $msg) {
}

/**
* Enable nameserver merging
* Enable nameserver merging.
*
* @return void
*/
private function _mergeDns()
{
$optDir = '/opt/valet-linux';
$script = $optDir.'/valet-dns';
$optDir = '/opt/valet-linux';
$script = $optDir.'/valet-dns';

$this->pm->ensureInstalled('inotify-tools');
$this->files->remove($optDir);
$this->files->ensureDirExists($optDir);
$this->files->put($script, $this->files->get(__DIR__.'/../stubs/valet-dns'));
$this->cli->run("chmod +x $script");
$this->sm->installValetDns($this->files);

if ($this->files->exists($this->rclocal)) {
$this->files->restore($this->rclocal);
}

$this->files->backup($this->resolvconf);
$this->files->unlink($this->resolvconf);
$this->files->symlink($script, $this->resolvconf);
Expand Down Expand Up @@ -123,7 +123,6 @@ public function restart()
$this->sm->restart('dnsmasq');
}


/**
* Append the custom DnsMasq configuration file to the main configuration file.
*
Expand Down Expand Up @@ -207,7 +206,7 @@ public function uninstall()
$this->files->unlink($this->dnsmasqOpts);
$this->files->unlink($this->nmConfigPath);
$this->files->restore($this->resolvedConfigPath);

$this->_lockResolvConf(false);
$this->files->restore($this->rclocal);
$this->files->restore($this->resolvconf);
Expand Down

0 comments on commit e237cbd

Please sign in to comment.