Skip to content

Commit 01de86c

Browse files
committed
Added PHP_CodeSniffer configuration with PSR-12 as the target
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.
1 parent 06097bd commit 01de86c

147 files changed

Lines changed: 1461 additions & 954 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/build
44
.onion
55
.phpbrew
6+
.phpcs.cache
67
tags
78
/build/logs
89
*.phar

phpcs.xml.dist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="."/>
4+
<arg name="colors"/>
5+
<arg value="ps"/>
6+
<arg name="cache" value=".phpcs.cache"/>
7+
8+
<file>src</file>
9+
<file>tests</file>
10+
11+
<rule ref="PSR12">
12+
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>
13+
</rule>
14+
15+
<rule ref="Generic.Files.LineLength.TooLong">
16+
<exclude-pattern>src/PhpBrew/Topic/*</exclude-pattern>
17+
</rule>
18+
19+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
20+
<exclude-pattern>tests/*</exclude-pattern>
21+
</rule>
22+
23+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
24+
<exclude-pattern>src/PhpBrew/Utils.php</exclude-pattern>
25+
</rule>
26+
</ruleset>

src/PhpBrew/AppStore.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,26 @@ public static function all()
1010
'composer' => array('url' => 'https://getcomposer.org/composer.phar', 'as' => 'composer'),
1111
'phpunit' => array('url' => 'https://phar.phpunit.de/phpunit.phar', 'as' => 'phpunit'),
1212
'phpmd' => array('url' => 'http://static.phpmd.org/php/latest/phpmd.phar', 'as' => 'phpmd'),
13-
'behat-2.5' => array('url' => 'https://github.com/Behat/Behat/releases/download/v2.5.5/behat.phar', 'as' => 'behat'),
14-
'behat-3.3' => array('url' => 'https://github.com/Behat/Behat/releases/download/v3.3.0/behat.phar', 'as' => 'behat'),
13+
'behat-2.5' => array(
14+
'url' => 'https://github.com/Behat/Behat/releases/download/v2.5.5/behat.phar',
15+
'as' => 'behat',
16+
),
17+
'behat-3.3' => array(
18+
'url' => 'https://github.com/Behat/Behat/releases/download/v3.3.0/behat.phar',
19+
'as' => 'behat',
20+
),
1521
'sami' => array('url' => 'http://get.sensiolabs.org/sami.phar', 'as' => 'sami'),
1622
'phpcs' => array('url' => 'https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar', 'as' => 'phpcs'),
1723
'phpcbf' => array('url' => 'https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar', 'as' => 'phpcbf'),
1824
'pdepend' => array('url' => 'http://static.pdepend.org/php/latest/pdepend.phar', 'as' => 'pdepend'),
19-
'onion' => array('url' => 'https://raw.githubusercontent.com/phpbrew/Onion/master/onion', 'as' => 'onion'),
20-
'box-2.7' => array('url' => 'https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar', 'as' => 'box'),
25+
'onion' => array(
26+
'url' => 'https://raw.githubusercontent.com/phpbrew/Onion/master/onion',
27+
'as' => 'onion',
28+
),
29+
'box-2.7' => array(
30+
'url' => 'https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar',
31+
'as' => 'box',
32+
),
2133
'psysh' => array('url' => 'https://psysh.org/psysh', 'as' => 'psysh'),
2234
'phpdoc' => array('url' => 'http://www.phpdoc.org/phpDocumentor.phar', 'as' => 'phpdoc')
2335
);

src/PhpBrew/Build.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace PhpBrew;
44

5-
use Serializable;
65
use PhpBrew\BuildSettings\BuildSettings;
6+
use Serializable;
77

88
/**
99
* A build object contains version information,
@@ -152,12 +152,12 @@ public function getSourceDirectory()
152152

153153
public function isBuildable()
154154
{
155-
return file_exists($this->sourceDirectory.DIRECTORY_SEPARATOR.'Makefile');
155+
return file_exists($this->sourceDirectory . DIRECTORY_SEPARATOR . 'Makefile');
156156
}
157157

158158
public function getBuildLogPath()
159159
{
160-
$dir = $this->getSourceDirectory().DIRECTORY_SEPARATOR.'build.log';
160+
$dir = $this->getSourceDirectory() . DIRECTORY_SEPARATOR . 'build.log';
161161
return $dir;
162162
}
163163

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

169169
public function getBinDirectory()
170170
{
171-
return $this->installPrefix.DIRECTORY_SEPARATOR.'bin';
171+
return $this->installPrefix . DIRECTORY_SEPARATOR . 'bin';
172172
}
173173

174174
public function getEtcDirectory()
175175
{
176-
$etc = $this->installPrefix.DIRECTORY_SEPARATOR.'etc';
176+
$etc = $this->installPrefix . DIRECTORY_SEPARATOR . 'etc';
177177
if (!file_exists($etc)) {
178178
mkdir($etc, 0755, true);
179179
}
@@ -183,12 +183,12 @@ public function getEtcDirectory()
183183

184184
public function getVarDirectory()
185185
{
186-
return $this->installPrefix.DIRECTORY_SEPARATOR.'var';
186+
return $this->installPrefix . DIRECTORY_SEPARATOR . 'var';
187187
}
188188

189189
public function getVarConfigDirectory()
190190
{
191-
return $this->installPrefix.DIRECTORY_SEPARATOR.'var'.DIRECTORY_SEPARATOR.'db';
191+
return $this->installPrefix . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'db';
192192
}
193193

194194
public function getInstallPrefix()
@@ -201,12 +201,12 @@ public function getInstallPrefix()
201201
*/
202202
public function getCurrentConfigScanPath()
203203
{
204-
return $this->installPrefix.DIRECTORY_SEPARATOR.'var'.DIRECTORY_SEPARATOR.'db';
204+
return $this->installPrefix . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'db';
205205
}
206206

207207
public function getPath($subpath)
208208
{
209-
return $this->installPrefix.DIRECTORY_SEPARATOR.$subpath;
209+
return $this->installPrefix . DIRECTORY_SEPARATOR . $subpath;
210210
}
211211

212212
/**
@@ -229,7 +229,7 @@ public function getIdentifier()
229229
$names[] = $n;
230230
} else {
231231
$v = preg_replace('#\W+#', '_', $v);
232-
$str = $n.'='.$v;
232+
$str = $n . '=' . $v;
233233
$names[] = $str;
234234
}
235235
}
@@ -246,7 +246,7 @@ public function getIdentifier()
246246

247247
public function getSourceExtensionDirectory()
248248
{
249-
return $this->sourceDirectory.DIRECTORY_SEPARATOR.'ext';
249+
return $this->sourceDirectory . DIRECTORY_SEPARATOR . 'ext';
250250
}
251251

252252
public function setBuildSettings(BuildSettings $settings)
@@ -259,7 +259,7 @@ public function setBuildSettings(BuildSettings $settings)
259259
// also contains the variant info,
260260
// but for backward compatibility, we still need a method to handle
261261
// the variant info file..
262-
$variantFile = $this->getInstallPrefix().DIRECTORY_SEPARATOR.'phpbrew.variants';
262+
$variantFile = $this->getInstallPrefix() . DIRECTORY_SEPARATOR . 'phpbrew.variants';
263263
if (file_exists($variantFile)) {
264264
$this->settings->loadVariantInfoFile($variantFile);
265265
}
@@ -329,7 +329,7 @@ public function import($data)
329329
public function getStateFile()
330330
{
331331
if ($dir = $this->getInstallPrefix()) {
332-
return $dir.DIRECTORY_SEPARATOR.'phpbrew_status';
332+
return $dir . DIRECTORY_SEPARATOR . 'phpbrew_status';
333333
}
334334
}
335335

src/PhpBrew/BuildFinder.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22

33
namespace PhpBrew;
44

5+
use Exception;
6+
57
class BuildFinder
68
{
79
/**
810
* @return string[]
911
*/
1012
public static function findInstalledBuilds($stripPrefix = true)
1113
{
12-
$path = Config::getRoot().DIRECTORY_SEPARATOR.'php';
14+
$path = Config::getRoot() . DIRECTORY_SEPARATOR . 'php';
1315
if (!file_exists($path)) {
14-
throw new \Exception($path.' does not exist.');
16+
throw new Exception($path . ' does not exist.');
1517
}
1618
$names = scandir($path);
1719
$names = array_filter($names, function ($name) use ($path) {
18-
return $name != '.' && $name != '..' && file_exists($path.DIRECTORY_SEPARATOR.$name.DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'php');
20+
return $name != '.'
21+
&& $name != '..'
22+
&& file_exists(
23+
$path
24+
. DIRECTORY_SEPARATOR . $name
25+
. DIRECTORY_SEPARATOR . 'bin'
26+
. DIRECTORY_SEPARATOR . 'php'
27+
);
1928
});
2029

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

3445
/**

src/PhpBrew/BuildRegister.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ class BuildRegister
1111
public function __construct()
1212
{
1313
$this->root = Config::getRoot();
14-
$this->baseDir = $this->root.DIRECTORY_SEPARATOR.'registry';
14+
$this->baseDir = $this->root . DIRECTORY_SEPARATOR . 'registry';
1515
}
1616

1717
public function register(Build $build)
1818
{
19-
$file = $this->baseDir.DIRECTORY_SEPARATOR.$build->getName();
19+
$file = $this->baseDir . DIRECTORY_SEPARATOR . $build->getName();
2020

2121
return $build->writeFile($file);
2222
}
2323

2424
public function deregister(Build $build)
2525
{
26-
$file = $this->baseDir.DIRECTORY_SEPARATOR.$build->getName();
26+
$file = $this->baseDir . DIRECTORY_SEPARATOR . $build->getName();
2727
if (file_exists($file)) {
2828
unlink($file);
2929

src/PhpBrew/BuildSettings/BuildSettings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PhpBrew\BuildSettings;
44

5+
use Exception;
6+
57
class BuildSettings
68
{
79
/**
@@ -185,7 +187,7 @@ public function grepExtraOptionsByPattern($pattern)
185187
public function loadVariantInfoFile($variantFile)
186188
{
187189
if (!is_readable($variantFile)) {
188-
throw new \Exception(
190+
throw new Exception(
189191
"Can't load variant info! Variants file {$variantFile} is not readable."
190192
);
191193
}

src/PhpBrew/Command/AppCommand/GetCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace PhpBrew\Command\AppCommand;
44

5-
use PhpBrew\Downloader\DownloadFactory;
6-
use PhpBrew\Config;
7-
use PhpBrew\AppStore;
85
use CLIFramework\Command;
96
use Exception;
7+
use PhpBrew\AppStore;
8+
use PhpBrew\Config;
9+
use PhpBrew\Downloader\DownloadFactory;
1010

1111
class GetCommand extends Command
1212
{
@@ -35,11 +35,12 @@ public function execute($appName)
3535
$apps = AppStore::all();
3636

3737
if (!isset($apps[$appName])) {
38-
throw new \Exception("App $appName not found.");
38+
throw new Exception("App $appName not found.");
3939
}
40+
4041
$app = $apps[$appName];
41-
$targetDir = Config::getRoot().DIRECTORY_SEPARATOR.'bin';
42-
$target = $targetDir.DIRECTORY_SEPARATOR.$app['as'];
42+
$targetDir = Config::getRoot() . DIRECTORY_SEPARATOR . 'bin';
43+
$target = $targetDir . DIRECTORY_SEPARATOR . $app['as'];
4344

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

src/PhpBrew/Command/AppCommand/ListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace PhpBrew\Command\AppCommand;
44

5-
use PhpBrew\AppStore;
65
use CLIFramework\Command;
6+
use PhpBrew\AppStore;
77

88
class ListCommand extends Command
99
{

src/PhpBrew/Command/CleanCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace PhpBrew\Command;
44

5-
use PhpBrew\Tasks\MakeTask;
5+
use CLIFramework\Command;
66
use PhpBrew\Build;
77
use PhpBrew\Config;
8+
use PhpBrew\Tasks\MakeTask;
89
use PhpBrew\Utils;
9-
use CLIFramework\Command;
1010

1111
class CleanCommand extends Command
1212
{
@@ -29,19 +29,19 @@ public function arguments($args)
2929
{
3030
$args->add('installed php')
3131
->validValues(function () {
32-
return \PhpBrew\Config::getInstalledPhpVersions();
32+
return Config::getInstalledPhpVersions();
3333
})
3434
;
3535
}
3636

3737
public function execute($version)
3838
{
39-
$buildDir = Config::getBuildDir().DIRECTORY_SEPARATOR.$version;
39+
$buildDir = Config::getBuildDir() . DIRECTORY_SEPARATOR . $version;
4040
if ($this->options->all) {
4141
if (!file_exists($buildDir)) {
42-
$this->logger->info('Source directory '.$buildDir.' does not exist.');
42+
$this->logger->info('Source directory ' . $buildDir . ' does not exist.');
4343
} else {
44-
$this->logger->info('Source directory '.$buildDir.' found, deleting...');
44+
$this->logger->info('Source directory ' . $buildDir . ' found, deleting...');
4545
Utils::recursive_unlink($buildDir, $this->logger);
4646
}
4747
} else {

0 commit comments

Comments
 (0)