Skip to content

Commit

Permalink
Add PHP_CodeSniffer and PSR-2 as project dependency (#399)
Browse files Browse the repository at this point in the history
* Add PHP_CodeSniffer as project dependency
* Refactor code with PSR-2 automated fixes by phpcbf command
* Refactor code for manual required PSR-2 rules
  • Loading branch information
Neodork authored Aug 26, 2019
1 parent edc7be6 commit 1999488
Show file tree
Hide file tree
Showing 44 changed files with 678 additions and 571 deletions.
30 changes: 16 additions & 14 deletions cli/Valet/AbstractPecl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ abstract class AbstractPecl

];

var $cli, $files;
public $cli;
public $files;

/**
* Create a new PECL instance.
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
Expand Down Expand Up @@ -63,20 +64,20 @@ protected function getExtensionType($extension)
*/
public function getPhpIniPath()
{
$file = str_replace("\n", '', $this->cli->runAsUser('pecl config-get php_ini'));
$file = str_replace("\n", '', $this->cli->runAsUser('pecl config-get php_ini'));

if($file) {
return $file;
}
if ($file) {
return $file;
}

$grep = $this->cli->runAsUser('php -i | grep php.ini');
preg_match('/Path => ([^\s]*)/',$grep, $match);
$grep = $this->cli->runAsUser('php -i | grep php.ini');
preg_match('/Path => ([^\s]*)/', $grep, $match);

if(empty($match[1])) {
return '';
}
if (empty($match[1])) {
return '';
}

$path = trim($match[1]);
$path = trim($match[1]);

return $path . '/php.ini';
}
Expand Down Expand Up @@ -130,7 +131,7 @@ public function getExtensionDirectory()
/**
* Uninstall all extensions defined in EXTENSIONS.
*/
function uninstallExtensions()
public function uninstallExtensions()
{
throw new \Exception(__METHOD__.' not implemented!');
}
Expand All @@ -141,7 +142,8 @@ function uninstallExtensions()
* @param bool $onlyDefaults
* @throws Exception if not overridden but used.
*/
public function installExtensions($onlyDefaults = true){
public function installExtensions($onlyDefaults = true)
{
throw new \Exception(__METHOD__.' not implemented!');
}

Expand Down
26 changes: 13 additions & 13 deletions cli/Valet/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ abstract class AbstractService
const STATE_DISABLED = false;
const STATE_ENABLED = true;

var $configuration;
var $configClassName;
public $configuration;
public $configClassName;

/**
* AbstractService constructor.
*
* @param Configuration $configuration
*/
function __construct(Configuration $configuration)
public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
}
Expand All @@ -25,7 +25,7 @@ function __construct(Configuration $configuration)
*
* @return string
*/
function getConfigClassName()
public function getConfigClassName()
{
if (!$this->configClassName) {
try {
Expand All @@ -44,7 +44,7 @@ function getConfigClassName()
*
* @return bool
*/
function isEnabled()
public function isEnabled()
{
$config = $this->configuration->read();
$name = $this->getConfigClassName();
Expand All @@ -57,7 +57,7 @@ function isEnabled()
*
* @param $state
*/
function setEnabled($state)
public function setEnabled($state)
{
$config = $this->configuration->read();
$name = $this->getConfigClassName();
Expand All @@ -71,7 +71,7 @@ function setEnabled($state)
/**
* Stops the service and stores in configuration it should not be started.
*/
function disable()
public function disable()
{
$this->stop();
$this->setEnabled(self::STATE_DISABLED);
Expand All @@ -80,7 +80,7 @@ function disable()
/**
* Installs the service if not installed, restarts it and stores in configuration it should be started.
*/
function enable()
public function enable()
{
$this->setEnabled(self::STATE_ENABLED);
if ($this->installed()) {
Expand All @@ -94,21 +94,21 @@ function enable()
/**
* Implement installation of the service.
*/
abstract function install();
abstract public function install();

/**
* Implement wether or not the service is installed.
* @return bool
*/
abstract function installed();
abstract public function installed();

/**
* Implement stopping the service.
*/
abstract function stop();
abstract public function stop();

/**
* Implement restarting the service.
*/
abstract function restart();
}
abstract public function restart();
}
16 changes: 8 additions & 8 deletions cli/Valet/Binaries.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ class Binaries
]
];

var $cli, $files;
public $cli;
public $files;

/**
* Create a new Brew instance.
*
* @param CommandLine $cli
* @param Filesystem $files
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
Expand All @@ -70,15 +71,15 @@ function __construct(CommandLine $cli, Filesystem $files)
* @return bool
* True if installed, false if not installed.
*/
function installed($binary)
public function installed($binary)
{
return $this->files->exists(self::SUPPORTED_CUSTOM_BINARIES[$binary]['bin_location'] . $binary);
}

/**
* Install all binaries defined in SUPPORTED_CUSTOM_BINARIES
*/
function installBinaries()
public function installBinaries()
{
info("[binaries] Installing binaries");
foreach (self::SUPPORTED_CUSTOM_BINARIES as $binary => $versions) {
Expand All @@ -94,7 +95,7 @@ function installBinaries()
* @param $binary
* The binary key name.
*/
function installBinary($binary)
public function installBinary($binary)
{
$url = $this->getUrl($binary);
$urlSplit = explode('/', $url);
Expand Down Expand Up @@ -124,7 +125,7 @@ function installBinary($binary)
/**
* Uninstall all binaries defined in SUPPORTED_CUSTOM_BINARIES
*/
function uninstallBinaries()
public function uninstallBinaries()
{
info("[binaries] Uninstalling binaries");
foreach (self::SUPPORTED_CUSTOM_BINARIES as $binary => $versions) {
Expand All @@ -140,7 +141,7 @@ function uninstallBinaries()
* @param $binary
* The binary key name.
*/
function uninstallBinary($binary)
public function uninstallBinary($binary)
{
$binaryLocation = $this->getBinLocation($binary);
$this->cli->runAsUser('rm ' . $binaryLocation);
Expand Down Expand Up @@ -217,4 +218,3 @@ private function getBinLocation($binary)
throw new DomainException('bin_location key is required for binaries.');
}
}

31 changes: 16 additions & 15 deletions cli/Valet/Brew.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
class Brew
{

var $cli, $files;
public $cli;
public $files;

/**
* Create a new Brew instance.
*
* @param CommandLine $cli
* @param Filesystem $files
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
Expand All @@ -27,7 +28,7 @@ function __construct(CommandLine $cli, Filesystem $files)
* @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 @@ -37,7 +38,7 @@ function installed($formula)
*
* @return bool
*/
function hasInstalledNginx()
public function hasInstalledNginx()
{
return $this->installed('nginx')
|| $this->installed('nginx-full');
Expand All @@ -48,7 +49,7 @@ function hasInstalledNginx()
*
* @return string
*/
function nginxServiceName()
public function nginxServiceName()
{
return $this->installed('nginx-full') ? 'nginx-full' : 'nginx';
}
Expand All @@ -61,7 +62,7 @@ function nginxServiceName()
* @param array $taps
* @return void
*/
function ensureInstalled($formula, $options = [], $taps = [])
public function ensureInstalled($formula, $options = [], $taps = [])
{
if (!$this->installed($formula)) {
$this->installOrFail($formula, $options, $taps);
Expand All @@ -76,7 +77,7 @@ function ensureInstalled($formula, $options = [], $taps = [])
* @param array $taps
* @return void
*/
function ensureUninstalled($formula, $options = [], $taps = [])
public function ensureUninstalled($formula, $options = [], $taps = [])
{
if ($this->installed($formula)) {
$this->uninstallOrFail($formula, $options, $taps);
Expand All @@ -91,7 +92,7 @@ function ensureUninstalled($formula, $options = [], $taps = [])
* @param array $taps
* @return void
*/
function installOrFail($formula, $options = [], $taps = [])
public function installOrFail($formula, $options = [], $taps = [])
{
info('[' . $formula . '] Installing');

Expand All @@ -117,7 +118,7 @@ function ($exitCode, $errorOutput) use ($formula) {
* @param array $taps
* @return void
*/
function uninstallOrFail($formula, $options = [], $taps = [])
public function uninstallOrFail($formula, $options = [], $taps = [])
{
info('[' . $formula . '] Uninstalling');

Expand All @@ -141,7 +142,7 @@ function ($exitCode, $errorOutput) use ($formula) {
* @param dynamic [string] $formula
* @return void
*/
function tap($formulas)
public function tap($formulas)
{
$formulas = is_array($formulas) ? $formulas : func_get_args();

Expand All @@ -156,7 +157,7 @@ function tap($formulas)
* @param dynamic [string] $formula
* @return void
*/
function unTap($formulas)
public function unTap($formulas)
{
$formulas = is_array($formulas) ? $formulas : func_get_args();

Expand All @@ -171,7 +172,7 @@ function unTap($formulas)
* @param $formula
* @return bool
*/
function hasTap($formula)
public function hasTap($formula)
{
return strpos($this->cli->runAsUser("brew tap | grep $formula"), $formula) !== false;
}
Expand All @@ -181,7 +182,7 @@ function hasTap($formula)
*
* @param
*/
function restartService($services)
public function restartService($services)
{
$services = is_array($services) ? $services : func_get_args();

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

Expand All @@ -219,7 +220,7 @@ function stopService($services)
* @param $formula
* @return bool
*/
function isStartedService($formula)
public function isStartedService($formula)
{
$info = explode(" ", trim(str_replace($formula, "", $this->cli->runAsUser('brew services list | grep ' . $formula))));
$state = array_shift($info);
Expand Down
Loading

0 comments on commit 1999488

Please sign in to comment.