diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fc5c5e1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.php text eol=lf +*.xml text eol=lf diff --git a/Makefile b/Makefile index af01ab3..b7262a4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PHP_IMAGE_TAG=flyeralarm/php-code-valiator-cli:$(PHP_VERSION) -PHP_VERSION?=8.2 +PHP_VERSION?=8.3 PHP_BIN=$(RUNNER) php COMPOSER_BIN=$(RUNNER) /usr/bin/composer @@ -40,6 +40,7 @@ test: .PHONY: test-all test-all: + PHP_VERSION=8.3 $(MAKE) build update sniff test PHP_VERSION=8.2 $(MAKE) build update sniff test PHP_VERSION=8.1 $(MAKE) build update sniff test PHP_VERSION=7.4 $(MAKE) build update sniff test diff --git a/README.md b/README.md index 15d3e93..49b9b87 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ interpreted as described in [RFC 2119](http://www.ietf.org/rfc/rfc2119.txt). To prepare run command: ```bash +make build make install ``` diff --git a/composer.lock b/composer.lock index 6f80a7f..4d94c98 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "3.7.2", + "version": "3.11.1", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "19473c30efe4f7b3cd42522d0b2e6e7f243c6f87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/19473c30efe4f7b3cd42522d0b2e6e7f243c6f87", + "reference": "19473c30efe4f7b3cd42522d0b2e6e7f243c6f87", "shasum": "" }, "require": { @@ -27,11 +27,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -46,31 +46,54 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", "standards", "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, - "time": "2023-02-22T23:07:41+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-11-16T12:02:36+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php b/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php index 2a63a02..2605779 100644 --- a/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php @@ -2,8 +2,8 @@ namespace Flyeralarm\CodingGuidelines\Flyeralarm\Sniffs\ControlStructures; -use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; class YodaSniff implements Sniff { @@ -15,6 +15,7 @@ public function register() return [T_IF, T_ELSEIF, T_WHILE]; } + /** * @param File $phpcsFile * @param int $stackPtr @@ -25,7 +26,7 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $startOfConditionPtr = $stackPtr; - $endPtr = $tokens[$startOfConditionPtr]['scope_opener'] + 1; + $endPtr = $this->getConditionStartPointerDoWhileStable($tokens[$startOfConditionPtr]); $logicalOperatorTokenIds = [T_BOOLEAN_AND, T_BOOLEAN_OR, T_LOGICAL_AND, T_LOGICAL_OR, T_LOGICAL_XOR]; $scopeOpenerTokenIds = [T_OPEN_CURLY_BRACKET]; @@ -37,6 +38,7 @@ public function process(File $phpcsFile, $stackPtr) } } + /** * @param File $phpcsFile * @param $startOfConditionPtr @@ -115,4 +117,14 @@ private function checkConditionalOrderForArithmeticExpression( 'ConditionalOrder' ); } + + + private function getConditionStartPointerDoWhileStable(array $array): ?int + { + if (array_key_exists('scope_opener', $array)) { + return $array['scope_opener'] + 1; + } + + return null; + } } diff --git a/tests/rules/control-structures/yoda/allowed/DoWhile.php b/tests/rules/control-structures/yoda/allowed/DoWhile.php new file mode 100644 index 0000000..22488df --- /dev/null +++ b/tests/rules/control-structures/yoda/allowed/DoWhile.php @@ -0,0 +1,10 @@ + 0);