Skip to content

Use PHP-Code-Style 2.0 #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ jobs:
ini-values: error_reporting=-1, display_errors=On, zend.assertions=1
coverage: none

# Remove PHPCS as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3.
# Remove the PHPCS standard as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3.
- name: 'Composer: remove PHPCS'
if: ${{ matrix.php < 5.4 }}
run: composer remove --dev squizlabs/php_codesniffer --no-update --no-interaction
run: composer remove --dev php-parallel-lint/php-code-style --no-update --no-interaction

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
Expand Down
1 change: 1 addition & 0 deletions bin/skip-linting.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$stdin = fopen('php://stdin', 'r');
$input = stream_get_contents($stdin);
fclose($stdin);
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
"require-dev": {
"nette/tester": "^1.3 || ^2.0",
"php-parallel-lint/php-console-highlighter": "0.* || ^1.0",
"squizlabs/php_codesniffer": "^3.6"
"php-parallel-lint/php-code-style": "^2.0"
},
"suggest": {
"php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload": {
"psr-4": {
Expand Down
105 changes: 54 additions & 51 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP-Parallel-Lint" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
<ruleset name="PHP-Parallel-Lint">
<description>PHP Parallel Lint coding standard.</description>

<!--
Expand All @@ -9,9 +9,10 @@
#############################################################################
-->

<!-- Scan all files. -->
<file>.</file>

<!-- Exclude the Examples directory and the Composer vendor directory. -->
<!-- Exclude dependencies, test fixtures. -->
<exclude-pattern>*/tests/examples/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

Expand All @@ -27,77 +28,79 @@
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>


<!--
#############################################################################
RULES
USE THE PHPParallelLint RULESET
#############################################################################
-->

<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
<rule ref="PEAR.Functions.FunctionDeclaration"/>
<rule ref="PEAR.Functions.FunctionCallSignature"/>
<rule ref="PEAR.Functions.FunctionCallSignature.Indent">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity>0</severity>
<!-- Set the supported PHP versions for PHPCompatibility (included in PHPParallelLint). -->
<config name="testVersion" value="5.3-"/>

<rule ref="PHPParallelLint">
<!-- For improved readability, a blank line should be allowed before the next leaf in a if/else control structure. -->
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>

<!-- This package includes a polyfill for the JsonSerializable interface. -->
<exclude name="PHPCompatibility.Interfaces.NewInterfaces.jsonserializableFound"/>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>

<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.PHP.NoSilencedErrors">
<exclude-pattern>/bin/skip-linting\.php$</exclude-pattern>
</rule>
<rule ref="Squiz.PHP.GlobalKeyword"/>
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
<rule ref="Squiz.PHP.NonExecutableCode"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>

<rule ref="Generic.Strings.UnnecessaryStringConcat"/>

<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="PEAR.WhiteSpace.ScopeClosingBrace"/>

<rule ref="PEAR.Classes.ClassDeclaration"/>

<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="PEAR.ControlStructures.ControlSignature"/>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="135"/>
<property name="absoluteLineLimit" value="200"/>
</properties>
</rule>
<rule ref="Zend.Files.ClosingTag"/>
<rule ref="Generic.Files.LineEndings"/>

<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>

<rule ref="Generic.Metrics.NestingLevel"/>
<!--
#############################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
#############################################################################
-->

<!-- Polyfill for PHP native interface, can't be in a namespace. -->
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>src/polyfill\.php$</exclude-pattern>
</rule>

<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>

<rule ref="PEAR.Commenting.InlineComment"/>
<!--
#############################################################################
TEMPORARY EXCLUSIONS
These adjustments should be removed once the codebase has been fixed up.
#############################################################################
-->

<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<!-- To be addressed at a later point in time. -->
<rule ref="Generic.Metrics.CyclomaticComplexity">
<exclude-pattern>/src/(Application|ParallelLint|Settings|Outputs/TextOutput)\.php$</exclude-pattern>
</rule>

<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.ControlStructures.ElseIfDeclaration"/>
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
<!-- To be addressed in test refactor. -->
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>/tests/Output\.phpt$</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>/tests/*\.php[t]?$</exclude-pattern>
</rule>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>/tests/*\.phpt$</exclude-pattern>
</rule>
<rule ref="PSR12.Files.FileHeader.SpacingAfterBlock">
<exclude-pattern>/tests/skip-on-5.3/trait\.php$</exclude-pattern>
</rule>
<rule ref="PSR12.Files.OpenTag.NotAlone">
<exclude-pattern>/tests/skip-on-5.3/trait\.php$</exclude-pattern>
</rule>
<rule ref="PHPCompatibility.Keywords.NewKeywords.t_traitFound">
<exclude-pattern>/tests/skip-on-5.3/trait\.php$</exclude-pattern>
</rule>

</ruleset>
4 changes: 2 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function run()
$this->showUsage();
return self::FAILED;
}
$manager = new Manager;
$manager = new Manager();
$result = $manager->run($settings);
if ($settings->ignoreFails) {
return $result->hasSyntaxError() ? self::WITH_ERRORS : self::SUCCESS;
Expand Down Expand Up @@ -112,7 +112,7 @@ private function showOptions()
*/
private function showVersion()
{
echo 'PHP Parallel Lint version ' . self::VERSION.PHP_EOL;
echo 'PHP Parallel Lint version ', self::VERSION, PHP_EOL;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Blame.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint;

use ReturnTypeWillChange;
Expand All @@ -24,7 +25,7 @@ class Blame implements \JsonSerializable
* which is a value of any type other than a resource.
*/
#[ReturnTypeWillChange]
function jsonSerialize()
public function jsonSerialize()
{
return array(
'name' => $this->name,
Expand Down
1 change: 1 addition & 0 deletions src/Contracts/SyntaxErrorCallback.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Contracts;

use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
Expand Down
3 changes: 2 additions & 1 deletion src/ErrorFormatter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint;

use JakubOnderka\PhpConsoleColor\ConsoleColor as OldConsoleColor;
Expand Down Expand Up @@ -123,7 +124,7 @@ class_exists('\PHP_Parallel_Lint\PhpConsoleHighlighter\Highlighter')
$colors = new ConsoleColor();
$colors->setForceStyle($this->forceColors);
$highlighter = new Highlighter($colors);
} else if (
} elseif (
class_exists('\JakubOnderka\PhpConsoleHighlighter\Highlighter')
&& class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')
) {
Expand Down
1 change: 1 addition & 0 deletions src/Errors/ParallelLintError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Errors;

use ReturnTypeWillChange;
Expand Down
3 changes: 2 additions & 1 deletion src/Errors/SyntaxError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Errors;

use PHP_Parallel_Lint\PhpParallelLint\Blame;
Expand Down Expand Up @@ -121,4 +122,4 @@ public function jsonSerialize()
'blame' => $this->blame,
);
}
}
}
1 change: 1 addition & 0 deletions src/Exceptions/CallbackNotImplementedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class CallbackNotImplementedException extends ParallelLintException
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/ClassNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class ClassNotFoundException extends ParallelLintException
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class InvalidArgumentException extends ParallelLintException
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/ParallelLintException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

use ReturnTypeWillChange;
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/PathNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class PathNotFoundException extends ParallelLintException
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class RuntimeException extends ParallelLintException
{

}
1 change: 1 addition & 0 deletions src/Iterators/ArrayIterator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Iterators;

class ArrayIterator extends \ArrayIterator
Expand Down
15 changes: 8 additions & 7 deletions src/Manager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint;

use PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback;
Expand Down Expand Up @@ -30,7 +31,7 @@ class Manager
*/
public function run(Settings $settings = null)
{
$settings = $settings ?: new Settings;
$settings = $settings ?: new Settings();
$output = $this->output ?: $this->getDefaultOutput($settings);

$phpExecutable = PhpExecutable::getPhpExecutable($settings->phpExecutable);
Expand All @@ -56,9 +57,9 @@ public function run(Settings $settings = null)
$parallelLint->setProcessCallback(function ($status, $file) use ($output) {
if ($status === ParallelLint::STATUS_OK) {
$output->ok();
} else if ($status === ParallelLint::STATUS_SKIP) {
} elseif ($status === ParallelLint::STATUS_SKIP) {
$output->skip();
} else if ($status === ParallelLint::STATUS_ERROR) {
} elseif ($status === ParallelLint::STATUS_ERROR) {
$output->error();
} else {
$output->fail();
Expand Down Expand Up @@ -90,7 +91,7 @@ public function setOutput(OutputInterface $output)
*/
protected function getDefaultOutput(Settings $settings)
{
$writer = new ConsoleWriter;
$writer = new ConsoleWriter();
switch ($settings->format) {
case Settings::FORMAT_JSON:
return new JsonOutput($writer);
Expand Down Expand Up @@ -128,7 +129,7 @@ protected function gitBlame(Result $result, Settings $settings)
$process->waitForFinish();

if ($process->isSuccess()) {
$blame = new Blame;
$blame = new Blame();
$blame->name = $process->getAuthor();
$blame->email = $process->getAuthorEmail();
$blame->datetime = $process->getAuthorTime();
Expand Down Expand Up @@ -157,7 +158,7 @@ protected function getFilesFromPaths(array $paths, array $extensions, array $exc
foreach ($paths as $path) {
if (is_file($path)) {
$files[] = $path;
} else if (is_dir($path)) {
} elseif (is_dir($path)) {
$iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS);
if (!empty($excluded)) {
$iterator = new RecursiveDirectoryFilterIterator($iterator, $excluded);
Expand Down Expand Up @@ -202,7 +203,7 @@ protected function createSyntaxErrorCallback(Settings $settings)
throw new ClassNotFoundException($expectedClassName, $settings->syntaxErrorCallbackFile);
}

$callbackInstance = new $expectedClassName;
$callbackInstance = new $expectedClassName();

if (!($callbackInstance instanceof SyntaxErrorCallback)) {
throw new CallbackNotImplementedException($expectedClassName);
Expand Down
1 change: 1 addition & 0 deletions src/Outputs/CheckstyleOutput.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Outputs;

use PHP_Parallel_Lint\PhpParallelLint\ErrorFormatter;
Expand Down
1 change: 1 addition & 0 deletions src/Outputs/GitLabOutput.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Outputs;

use PHP_Parallel_Lint\PhpParallelLint\Outputs\OutputInterface;
Expand Down
Loading