Skip to content
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ PHPCSExtra is a collection of sniffs and standards for use with [PHP_CodeSniffer
## Minimum Requirements

* PHP 5.4 or higher.
* [PHP_CodeSniffer][phpcs-gh] version **3.13.0** or higher.
* [PHPCSUtils][phpcsutils-gh] version **1.1.0** or higher.
* [PHP_CodeSniffer][phpcs-gh] version **3.13.4** or higher.
* [PHPCSUtils][phpcsutils-gh] version **1.1.2** or higher.


## Installation
Expand All @@ -58,15 +58,15 @@ Installing via Composer is highly recommended.
Run the following from the root of your project:
```bash
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev phpcsstandards/phpcsextra:"^1.2.0"
composer require --dev phpcsstandards/phpcsextra:"^1.3.0"
```

### Composer Global Installation

Alternatively, you may want to install this standard globally:
```bash
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev phpcsstandards/phpcsextra:"^1.2.0"
composer global require --dev phpcsstandards/phpcsextra:"^1.3.0"
```

### Updating to a newer version
Expand Down
35 changes: 21 additions & 14 deletions Universal/Sniffs/PHP/NoFQNTrueFalseNullSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSExtra\Universal\Sniffs\PHP;

use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
Expand All @@ -31,18 +32,17 @@ final class NoFQNTrueFalseNullSniff implements Sniff
*/
public function register()
{
return [
// PHPCS 3.x on PHP < 8.0.
$targets = [
\T_TRUE,
\T_FALSE,
\T_NULL,
];

// PHPCS 3.x on PHP >= 8.0.
\T_STRING,
if (\version_compare(Config::VERSION, '4.0.0', '>=') === true) {
$targets[] = \T_NS_SEPARATOR;
}

// PHPCS 4.x.
\T_NAME_FULLY_QUALIFIED,
];
return $targets;
}

/**
Expand All @@ -62,17 +62,21 @@ public function process(File $phpcsFile, $stackPtr)
$content = $tokens[$stackPtr]['content'];
$contentLC = \strtolower($content);

if ($tokens[$stackPtr]['code'] === \T_NAME_FULLY_QUALIFIED) {
if ($contentLC === '\true' || $contentLC === '\false' || $contentLC === '\null') {
// PHPCS 4.x.
if ($contentLC !== '\true' && $contentLC !== '\false' && $contentLC !== '\null') {
} elseif ($tokens[$stackPtr]['code'] === \T_NS_SEPARATOR) {
// PHPCS 4.x for code which is a parse error on PHP 8.0+.
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($tokens[$next]['code'] !== \T_STRING) {
return;
}
} else {
// PHPCS 3.x.
if ($contentLC !== 'true' && $contentLC !== 'false' && $contentLC !== 'null') {

$nextContentLC = \strtolower($tokens[$next]['content']);
if ($nextContentLC !== 'true' && $nextContentLC !== 'false' && $nextContentLC !== 'null') {
return;
}

} else {
// PHPCS 3.x.
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$prev]['code'] !== \T_NS_SEPARATOR) {
return;
Expand All @@ -97,9 +101,12 @@ public function process(File $phpcsFile, $stackPtr)
);

if ($fix === true) {
if ($tokens[$stackPtr]['code'] === \T_NAME_FULLY_QUALIFIED) {
if ($contentLC === '\true' || $contentLC === '\false' || $contentLC === '\null') {
// PHPCS 4.x.
$phpcsFile->fixer->replaceToken($stackPtr, \ltrim($tokens[$stackPtr]['content'], '\\'));
} elseif ($tokens[$stackPtr]['code'] === \T_NS_SEPARATOR) {
// PHPCS 4.x for code which is a parse error on PHP 8.0+.
$phpcsFile->fixer->replaceToken($stackPtr, '');
} else {
// PHPCS 3.x.
$phpcsFile->fixer->replaceToken($prev, '');
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"require" : {
"php" : ">=5.4",
"squizlabs/php_codesniffer" : "^3.13.0 || ^4.0",
"phpcsstandards/phpcsutils" : "^1.1.0"
"squizlabs/php_codesniffer" : "^3.13.4 || ^4.0",
"phpcsstandards/phpcsutils" : "^1.1.2"
},
"require-dev" : {
"php-parallel-lint/php-parallel-lint": "^1.4.0",
Expand Down