Skip to content

Commit

Permalink
Added PHP_CodeSniffer configuration with PSR-12 as the target
Browse files Browse the repository at this point in the history
Additionally:

1. All class FQNs are replaced with imports.
2. Unused imports are removed.
3. Remaining imports are alphabetically sorted.
4. Expressions like `return $this->logger->error()` replaced with `$this->logger->error(); return` since most of the methods with such a combination do not return any value.
5. Removed doc-blocks autogenerated by PhpStorm.
  • Loading branch information
morozov committed Nov 12, 2019
1 parent 06097bd commit 01de86c
Show file tree
Hide file tree
Showing 147 changed files with 1,461 additions and 954 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@
/build
.onion
.phpbrew
.phpcs.cache
tags
/build/logs
*.phar
26 changes: 26 additions & 0 deletions phpcs.xml.dist
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="colors"/>
<arg value="ps"/>
<arg name="cache" value=".phpcs.cache"/>

<file>src</file>
<file>tests</file>

<rule ref="PSR12">
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>
</rule>

<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>src/PhpBrew/Topic/*</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>src/PhpBrew/Utils.php</exclude-pattern>
</rule>
</ruleset>
20 changes: 16 additions & 4 deletions src/PhpBrew/AppStore.php
Expand Up @@ -10,14 +10,26 @@ public static function all()
'composer' => array('url' => 'https://getcomposer.org/composer.phar', 'as' => 'composer'),
'phpunit' => array('url' => 'https://phar.phpunit.de/phpunit.phar', 'as' => 'phpunit'),
'phpmd' => array('url' => 'http://static.phpmd.org/php/latest/phpmd.phar', 'as' => 'phpmd'),
'behat-2.5' => array('url' => 'https://github.com/Behat/Behat/releases/download/v2.5.5/behat.phar', 'as' => 'behat'),
'behat-3.3' => array('url' => 'https://github.com/Behat/Behat/releases/download/v3.3.0/behat.phar', 'as' => 'behat'),
'behat-2.5' => array(
'url' => 'https://github.com/Behat/Behat/releases/download/v2.5.5/behat.phar',
'as' => 'behat',
),
'behat-3.3' => array(
'url' => 'https://github.com/Behat/Behat/releases/download/v3.3.0/behat.phar',
'as' => 'behat',
),
'sami' => array('url' => 'http://get.sensiolabs.org/sami.phar', 'as' => 'sami'),
'phpcs' => array('url' => 'https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar', 'as' => 'phpcs'),
'phpcbf' => array('url' => 'https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar', 'as' => 'phpcbf'),
'pdepend' => array('url' => 'http://static.pdepend.org/php/latest/pdepend.phar', 'as' => 'pdepend'),
'onion' => array('url' => 'https://raw.githubusercontent.com/phpbrew/Onion/master/onion', 'as' => 'onion'),
'box-2.7' => array('url' => 'https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar', 'as' => 'box'),
'onion' => array(
'url' => 'https://raw.githubusercontent.com/phpbrew/Onion/master/onion',
'as' => 'onion',
),
'box-2.7' => array(
'url' => 'https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar',
'as' => 'box',
),
'psysh' => array('url' => 'https://psysh.org/psysh', 'as' => 'psysh'),
'phpdoc' => array('url' => 'http://www.phpdoc.org/phpDocumentor.phar', 'as' => 'phpdoc')
);
Expand Down
26 changes: 13 additions & 13 deletions src/PhpBrew/Build.php
Expand Up @@ -2,8 +2,8 @@

namespace PhpBrew;

use Serializable;
use PhpBrew\BuildSettings\BuildSettings;
use Serializable;

/**
* A build object contains version information,
Expand Down Expand Up @@ -152,12 +152,12 @@ public function getSourceDirectory()

public function isBuildable()
{
return file_exists($this->sourceDirectory.DIRECTORY_SEPARATOR.'Makefile');
return file_exists($this->sourceDirectory . DIRECTORY_SEPARATOR . 'Makefile');
}

public function getBuildLogPath()
{
$dir = $this->getSourceDirectory().DIRECTORY_SEPARATOR.'build.log';
$dir = $this->getSourceDirectory() . DIRECTORY_SEPARATOR . 'build.log';
return $dir;
}

Expand All @@ -168,12 +168,12 @@ public function setInstallPrefix($prefix)

public function getBinDirectory()
{
return $this->installPrefix.DIRECTORY_SEPARATOR.'bin';
return $this->installPrefix . DIRECTORY_SEPARATOR . 'bin';
}

public function getEtcDirectory()
{
$etc = $this->installPrefix.DIRECTORY_SEPARATOR.'etc';
$etc = $this->installPrefix . DIRECTORY_SEPARATOR . 'etc';
if (!file_exists($etc)) {
mkdir($etc, 0755, true);
}
Expand All @@ -183,12 +183,12 @@ public function getEtcDirectory()

public function getVarDirectory()
{
return $this->installPrefix.DIRECTORY_SEPARATOR.'var';
return $this->installPrefix . DIRECTORY_SEPARATOR . 'var';
}

public function getVarConfigDirectory()
{
return $this->installPrefix.DIRECTORY_SEPARATOR.'var'.DIRECTORY_SEPARATOR.'db';
return $this->installPrefix . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'db';
}

public function getInstallPrefix()
Expand All @@ -201,12 +201,12 @@ public function getInstallPrefix()
*/
public function getCurrentConfigScanPath()
{
return $this->installPrefix.DIRECTORY_SEPARATOR.'var'.DIRECTORY_SEPARATOR.'db';
return $this->installPrefix . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'db';
}

public function getPath($subpath)
{
return $this->installPrefix.DIRECTORY_SEPARATOR.$subpath;
return $this->installPrefix . DIRECTORY_SEPARATOR . $subpath;
}

/**
Expand All @@ -229,7 +229,7 @@ public function getIdentifier()
$names[] = $n;
} else {
$v = preg_replace('#\W+#', '_', $v);
$str = $n.'='.$v;
$str = $n . '=' . $v;
$names[] = $str;
}
}
Expand All @@ -246,7 +246,7 @@ public function getIdentifier()

public function getSourceExtensionDirectory()
{
return $this->sourceDirectory.DIRECTORY_SEPARATOR.'ext';
return $this->sourceDirectory . DIRECTORY_SEPARATOR . 'ext';
}

public function setBuildSettings(BuildSettings $settings)
Expand All @@ -259,7 +259,7 @@ public function setBuildSettings(BuildSettings $settings)
// also contains the variant info,
// but for backward compatibility, we still need a method to handle
// the variant info file..
$variantFile = $this->getInstallPrefix().DIRECTORY_SEPARATOR.'phpbrew.variants';
$variantFile = $this->getInstallPrefix() . DIRECTORY_SEPARATOR . 'phpbrew.variants';
if (file_exists($variantFile)) {
$this->settings->loadVariantInfoFile($variantFile);
}
Expand Down Expand Up @@ -329,7 +329,7 @@ public function import($data)
public function getStateFile()
{
if ($dir = $this->getInstallPrefix()) {
return $dir.DIRECTORY_SEPARATOR.'phpbrew_status';
return $dir . DIRECTORY_SEPARATOR . 'phpbrew_status';
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/PhpBrew/BuildFinder.php
Expand Up @@ -2,20 +2,29 @@

namespace PhpBrew;

use Exception;

class BuildFinder
{
/**
* @return string[]
*/
public static function findInstalledBuilds($stripPrefix = true)
{
$path = Config::getRoot().DIRECTORY_SEPARATOR.'php';
$path = Config::getRoot() . DIRECTORY_SEPARATOR . 'php';
if (!file_exists($path)) {
throw new \Exception($path.' does not exist.');
throw new Exception($path . ' does not exist.');
}
$names = scandir($path);
$names = array_filter($names, function ($name) use ($path) {
return $name != '.' && $name != '..' && file_exists($path.DIRECTORY_SEPARATOR.$name.DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'php');
return $name != '.'
&& $name != '..'
&& file_exists(
$path
. DIRECTORY_SEPARATOR . $name
. DIRECTORY_SEPARATOR . 'bin'
. DIRECTORY_SEPARATOR . 'php'
);
});

if ($names == null || empty($names)) {
Expand All @@ -28,7 +37,9 @@ public static function findInstalledBuilds($stripPrefix = true)
}, $names);
}
uasort($names, 'version_compare'); // ordering version name ascending... 5.5.17, 5.5.12
return array_reverse($names); // make it descending... since there is no sort function for user-define in reverse order.

// make it descending... since there is no sort function for user-define in reverse order.
return array_reverse($names);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/PhpBrew/BuildRegister.php
Expand Up @@ -11,19 +11,19 @@ class BuildRegister
public function __construct()
{
$this->root = Config::getRoot();
$this->baseDir = $this->root.DIRECTORY_SEPARATOR.'registry';
$this->baseDir = $this->root . DIRECTORY_SEPARATOR . 'registry';
}

public function register(Build $build)
{
$file = $this->baseDir.DIRECTORY_SEPARATOR.$build->getName();
$file = $this->baseDir . DIRECTORY_SEPARATOR . $build->getName();

return $build->writeFile($file);
}

public function deregister(Build $build)
{
$file = $this->baseDir.DIRECTORY_SEPARATOR.$build->getName();
$file = $this->baseDir . DIRECTORY_SEPARATOR . $build->getName();
if (file_exists($file)) {
unlink($file);

Expand Down
4 changes: 3 additions & 1 deletion src/PhpBrew/BuildSettings/BuildSettings.php
Expand Up @@ -2,6 +2,8 @@

namespace PhpBrew\BuildSettings;

use Exception;

class BuildSettings
{
/**
Expand Down Expand Up @@ -185,7 +187,7 @@ public function grepExtraOptionsByPattern($pattern)
public function loadVariantInfoFile($variantFile)
{
if (!is_readable($variantFile)) {
throw new \Exception(
throw new Exception(
"Can't load variant info! Variants file {$variantFile} is not readable."
);
}
Expand Down
13 changes: 7 additions & 6 deletions src/PhpBrew/Command/AppCommand/GetCommand.php
Expand Up @@ -2,11 +2,11 @@

namespace PhpBrew\Command\AppCommand;

use PhpBrew\Downloader\DownloadFactory;
use PhpBrew\Config;
use PhpBrew\AppStore;
use CLIFramework\Command;
use Exception;
use PhpBrew\AppStore;
use PhpBrew\Config;
use PhpBrew\Downloader\DownloadFactory;

class GetCommand extends Command
{
Expand Down Expand Up @@ -35,11 +35,12 @@ public function execute($appName)
$apps = AppStore::all();

if (!isset($apps[$appName])) {
throw new \Exception("App $appName not found.");
throw new Exception("App $appName not found.");
}

$app = $apps[$appName];
$targetDir = Config::getRoot().DIRECTORY_SEPARATOR.'bin';
$target = $targetDir.DIRECTORY_SEPARATOR.$app['as'];
$targetDir = Config::getRoot() . DIRECTORY_SEPARATOR . 'bin';
$target = $targetDir . DIRECTORY_SEPARATOR . $app['as'];

DownloadFactory::getInstance($this->logger, $this->options)->download($app['url'], $target);

Expand Down
2 changes: 1 addition & 1 deletion src/PhpBrew/Command/AppCommand/ListCommand.php
Expand Up @@ -2,8 +2,8 @@

namespace PhpBrew\Command\AppCommand;

use PhpBrew\AppStore;
use CLIFramework\Command;
use PhpBrew\AppStore;

class ListCommand extends Command
{
Expand Down
12 changes: 6 additions & 6 deletions src/PhpBrew/Command/CleanCommand.php
Expand Up @@ -2,11 +2,11 @@

namespace PhpBrew\Command;

use PhpBrew\Tasks\MakeTask;
use CLIFramework\Command;
use PhpBrew\Build;
use PhpBrew\Config;
use PhpBrew\Tasks\MakeTask;
use PhpBrew\Utils;
use CLIFramework\Command;

class CleanCommand extends Command
{
Expand All @@ -29,19 +29,19 @@ public function arguments($args)
{
$args->add('installed php')
->validValues(function () {
return \PhpBrew\Config::getInstalledPhpVersions();
return Config::getInstalledPhpVersions();
})
;
}

public function execute($version)
{
$buildDir = Config::getBuildDir().DIRECTORY_SEPARATOR.$version;
$buildDir = Config::getBuildDir() . DIRECTORY_SEPARATOR . $version;
if ($this->options->all) {
if (!file_exists($buildDir)) {
$this->logger->info('Source directory '.$buildDir.' does not exist.');
$this->logger->info('Source directory ' . $buildDir . ' does not exist.');
} else {
$this->logger->info('Source directory '.$buildDir.' found, deleting...');
$this->logger->info('Source directory ' . $buildDir . ' found, deleting...');
Utils::recursive_unlink($buildDir, $this->logger);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpBrew/Command/ConfigCommand.php
Expand Up @@ -3,8 +3,8 @@
namespace PhpBrew\Command;

use CLIFramework\Command;
use PhpBrew\Utils;
use PhpBrew\Config;
use PhpBrew\Utils;

class ConfigCommand extends Command
{
Expand Down

0 comments on commit 01de86c

Please sign in to comment.