-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Composer: require PHPCSDevCS * PHPCS: switch to using the PHPCSDev standard This commit: * Switches out the `PSR2` ruleset in favour of the `PHPCSDev` ruleset. The PHPCSDev ruleset checks the following: > * Compliance with PSR-12, with a few select exceptions. > * Use of camelCase variable and function names. > * Use of normalized arrays. > * All files, classes, functions and properties are documented with a docblock and contain the minimally needed information. > * A number of arbitrary additional code style and QA checks. > * PHP cross-version compatibility, while allowing for tokens back-filled by PHPCS itself. * For the PHP cross-version compatibility check, the minimum supported PHP version (`testVersion`) is set to PHP 5.4, in line with the `require`ment for this package per the `composer.json` file. * In contrast to `PHPCSDev`/PSR12, the ruleset for the VariableAnalysis package will: - Enforce tabs instead of spaces. - Disallow a blank line at the start of a class. Note: this complies with PSR12. PHPCSDev already had the blank line enforcement in place prior to this being forbidden via the PSR12 standard, which is why it excludes the rule. - Not enforce most documentation checks. - Not enforce assignment operator alignment. * Additionally, for the time being, the PSR12 line length guidelines will not be enforced. Enforcing those needs additional (manual) adjustments to the codebase which can be done at a later point in time. * Adds some extra documention to the ruleset. Refs: * https://github.com/PHPCSStandards/PHPCSDevCS * https://github.com/PHPCSStandards/PHPCSDevCS/blob/main/PHPCSDev/ruleset.xml * CS: various minor whitespace fixes Minimal changes needed to comply with the PSR12/PHPCSDev whitespace rules. Most notably this commit adds a blank line between a PHP open tag and the namespace declaration as per the PSR12 file header rules. * CS: minor code restructuring [1] The `VariableAnalysisSniff::processVariableAsSuperGlobal()` method checks a variable name against a fixed array of names using `in_array()`. To comply with the updated CS rules, each parameter in the function call would need to be placed on a new line and the function call itself as well, making this a very drawn out condition. By restructuring the code to declare the array prior to the `in_array()` function call, this is no longer needed. Additional notes: * I've also changed the `in_array()` call to a _strict_ comparison by adding the third parameter and setting it to `true`. * I've simplified the `return` by removing the unnecessary condition and double return statements. * The array could/should probably be declared as a property instead of within the function. I've not done so at this time, as it could also be considered to switch over to using the PHPCSUtils `Variables::isSuperglobal()` or `Variables::isSuperglobalName()` methods in the future. Ref: * https://www.php.net/manual/en/function.in-array.php * https://phpcsutils.com/phpdoc/classes/PHPCSUtils-Utils-Variables.html#property_phpReservedVars * CS: minor code restructuring [2] Similar to the previous commit, the `VariableAnalysisSniff::processVariableAsStaticDeclaration()` method declares an array within a function call. This commit moves the array declaration out of the function call and leverages a pre-defined array from the PHPCS native `Tokens` class to retrieve a number of the tokens (heredoc and nowdoc tokens). Note: this commit does **not** fix known shortcomings of this method as reported in 158 and 253. Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
- Loading branch information
Showing
18 changed files
with
114 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/squizlabs/php_codesniffer/tests/bootstrap.php'; | ||
require_once __DIR__ . '/BaseTestCase.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters