-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from PHPCSStandards/feature/add-the-base-rulesets
Add the base rulesets
- Loading branch information
Showing
9 changed files
with
296 additions
and
4 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,2 +1,4 @@ | ||
vendor/ | ||
composer.lock | ||
/composer.lock | ||
/.phpcs.xml | ||
/phpcs.xml |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. | ||
* | ||
* @package PHPCSUtils | ||
* @copyright 2019 PHPCSUtils Contributors | ||
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 | ||
* @link https://github.com/PHPCSStandards/PHPCSUtils | ||
*/ | ||
|
||
namespace PHPCS23Utils\Sniffs\Load; | ||
|
||
/* | ||
* Here be magic. | ||
* | ||
* This include allows for the Utility functions to work PHPCS cross-version. | ||
*/ | ||
require_once \dirname(\dirname(\dirname(__DIR__))) . '/phpcsutils-autoload.php'; | ||
|
||
/** | ||
* Dummy Sniff. | ||
* | ||
* This sniff doesn't do anything. It's just here to trigger the above include. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
class LoadUtilsSniff | ||
{ | ||
|
||
/** | ||
* Returns an array of tokens this test wants to listen for. | ||
* | ||
* @return array | ||
*/ | ||
public function register() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Processes this test, when one of its tokens is encountered. | ||
* | ||
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. | ||
* @param int $stackPtr The position of the current token in | ||
* the stack passed in $tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function process($phpcsFile, $stackPtr) | ||
{ | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCS23Utils" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"> | ||
<description>Standard which makes the PHPCSUtils utility methods for external PHPCS standards available in PHPCS 2.x.</description> | ||
</ruleset> |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCSUtils" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"> | ||
<description>Utility methods for external PHPCS standards.</description> | ||
</ruleset> |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Coding Standard for PHPCSUtils" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"> | ||
<description>Check the code of the PHPCSUtils standard.</description> | ||
|
||
<!-- | ||
############################################################################# | ||
COMMAND LINE ARGUMENTS | ||
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml | ||
############################################################################# | ||
--> | ||
|
||
<file>.</file> | ||
|
||
<!-- Exclude Composer vendor directory. --> | ||
<exclude-pattern>*/vendor/*</exclude-pattern> | ||
|
||
<!-- Only check PHP files. --> | ||
<arg name="extensions" value="php"/> | ||
|
||
<!-- Show progress, show the error codes for each message (source). --> | ||
<arg value="ps"/> | ||
|
||
<!-- Strip the filepaths down to the relevant bit. --> | ||
<arg name="basepath" value="./"/> | ||
|
||
<!-- Check up to 8 files simultaneously. --> | ||
<arg name="parallel" value="8"/> | ||
|
||
<!-- | ||
############################################################################# | ||
USE THE PHPCSDev RULESET | ||
############################################################################# | ||
--> | ||
|
||
<rule ref="PHPCSDev"> | ||
<!-- Allow for the file docblock on the line directly following the PHP open tag. | ||
As the sniff in PHPCS does not use modular error codes (yet - see PR #2729), | ||
the complete error code needs to be disabled, not just the bit involving | ||
the file docblocks. | ||
--> | ||
<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/> | ||
</rule> | ||
|
||
<!-- Set minimum PHP version supported to PHP 5.4. --> | ||
<config name="testVersion" value="5.4-"/> | ||
|
||
<!-- Enforce short arrays. --> | ||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/> | ||
|
||
|
||
<!-- | ||
############################################################################# | ||
SELECTIVE EXCLUSIONS | ||
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs. | ||
############################################################################# | ||
--> | ||
|
||
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols"> | ||
<exclude-pattern>/phpcsutils-autoload\.php$</exclude-pattern> | ||
<exclude-pattern>/PHPCS23Utils/Sniffs/Load/LoadUtilsSniff\.php$</exclude-pattern> | ||
</rule> | ||
|
||
</ruleset> |
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. | ||
* | ||
* Autoloader for the PHPCSUtils files. | ||
* Also provides PHPCS cross-version class aliases. | ||
* | ||
* - If an external standard only supports PHPCS >= 3.1.0 and uses the PHPCS | ||
* native unit test framework, this file does not need to be included. | ||
* | ||
* - When PHPCS 2.x support is desired, include the "PHPCS23Utils" standard | ||
* in the ruleset of the external standard and this file will be included | ||
* automatically. | ||
* Including this file will allow PHPCSUtils to work in both PHPCS 2.x | ||
* as well as PHPCS 3.x. | ||
* | ||
* - If an external standard uses its own unit test setup, this file should | ||
* be included from the unit test bootstrap file. | ||
* | ||
* @package PHPCSUtils | ||
* @copyright 2019 PHPCSUtils Contributors | ||
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 | ||
* @link https://github.com/PHPCSStandards/PHPCSUtils | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
|
||
if (defined('PHPCSUTILS_AUTOLOAD') === false) { | ||
/* | ||
* Register an autoloader. | ||
* | ||
* External PHPCS standards which have their own unit test suite | ||
* should include this file in their test runner bootstrap. | ||
*/ | ||
spl_autoload_register(function ($class) { | ||
// Only try & load our own classes. | ||
if (stripos($class, 'PHPCSUtils') !== 0) { | ||
return; | ||
} | ||
|
||
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; | ||
|
||
if (file_exists($file)) { | ||
include_once $file; | ||
} | ||
}); | ||
|
||
define('PHPCSUTILS_AUTOLOAD', true); | ||
} | ||
|
||
if (defined('PHPCSUTILS_PHPCS_ALIASES_SET') === false) { | ||
/* | ||
* Alias a number of PHPCS 2.x classes to their PHPCS 3.x equivalents. | ||
* | ||
* {@internal The PHPCS file have been reorganized in PHPCS 3.x, quite | ||
* a few "old" classes have been split and spread out over several "new" | ||
* classes. In other words, this will only work for a limited number | ||
* of classes.}} | ||
* | ||
* {@internal The `class_exists` wrappers are needed to play nice with other | ||
* external PHPCS standards creating cross-version compatibility in a | ||
* similar manner.}} | ||
*/ | ||
if (interface_exists('\PHP_CodeSniffer_Sniff') === true | ||
&& interface_exists('\PHP_CodeSniffer\Sniffs\Sniff') === false | ||
) { | ||
class_alias('\PHP_CodeSniffer_Sniff', '\PHP_CodeSniffer\Sniffs\Sniff'); | ||
} | ||
|
||
if (class_exists('\PHP_CodeSniffer_File') === true | ||
&& class_exists('\PHP_CodeSniffer\Files\File') === false | ||
) { | ||
class_alias('\PHP_CodeSniffer_File', '\PHP_CodeSniffer\Files\File'); | ||
} | ||
|
||
if (class_exists('\PHP_CodeSniffer_Tokens') === true | ||
&& class_exists('\PHP_CodeSniffer\Util\Tokens') === false | ||
) { | ||
class_alias('\PHP_CodeSniffer_Tokens', '\PHP_CodeSniffer\Util\Tokens'); | ||
} | ||
|
||
if (class_exists('\PHP_CodeSniffer_Exception') === true | ||
&& class_exists('\PHP_CodeSniffer\Exceptions\RuntimeException') === false | ||
) { | ||
class_alias('\PHP_CodeSniffer_Exception', '\PHP_CodeSniffer\Exceptions\RuntimeException'); | ||
} | ||
|
||
if (class_exists('\PHP_CodeSniffer_Exception') === true | ||
&& class_exists('\PHP_CodeSniffer\Exceptions\TokenizerException') === false | ||
) { | ||
class_alias('\PHP_CodeSniffer_Exception', '\PHP_CodeSniffer\Exceptions\TokenizerException'); | ||
} | ||
|
||
define('PHPCSUTILS_PHPCS_ALIASES_SET', true); | ||
} |