diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2c383e7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: php -php: - - 7.1 - - 7.2 - - 7.3 - - nightly - -env: - - DEPENDENCIES= - - DEPENDENCIES=--prefer-lowest - -install: - composer update --no-interaction --prefer-stable --prefer-dist $DEPENDENCIES - -script: make test - -stages: - - Code Quality - - Test - -jobs: - allow_failures: - - php: nightly - - include: - - stage: Code Quality - name: Lint - php: 7.1 - script: make lint - - name: Coding Standard - php: 7.1 - script: make cs - - name: Static Analysis - php: 7.1 - script: make static-analysis diff --git a/src/Cdn77/Sniffs/Classes/ClassStructureSniff.php b/ExoSuiteCodingStandard/Sniffs/Classes/ClassStructureSniff.php similarity index 99% rename from src/Cdn77/Sniffs/Classes/ClassStructureSniff.php rename to ExoSuiteCodingStandard/Sniffs/Classes/ClassStructureSniff.php index f53877f..9d3d3f7 100644 --- a/src/Cdn77/Sniffs/Classes/ClassStructureSniff.php +++ b/ExoSuiteCodingStandard/Sniffs/Classes/ClassStructureSniff.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cdn77CodingStandard\Sniffs\Classes; +namespace ExoSuiteCodingStandard\Sniffs\Classes; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; diff --git a/ExoSuiteCodingStandard/ruleset.xml b/ExoSuiteCodingStandard/ruleset.xml new file mode 100644 index 0000000..b10a9d1 --- /dev/null +++ b/ExoSuiteCodingStandard/ruleset.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 0090181..0000000 --- a/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -COMPOSER_ARGS += --no-progress --no-interaction - -### BEGIN main targets - -.PHONY: build -build: vendor - @echo "Build successfully done." - -.PHONY: list -list: - @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' - -### END - -### BEGIN secondary targets - -.PHONY: vendor -vendor: vendor/lock - -vendor/lock: composer.json - composer install $(COMPOSER_ARGS) - touch vendor/lock - -### END - -### BEGIN tests - -.PHONY: test -test: - vendor/bin/phpunit $(PHPUNIT_ARGS) - -.PHONY: lint -lint: - vendor/bin/parallel-lint --exclude vendor . - -.PHONY: cs -cs: - vendor/bin/phpcs - -.PHONY: fix -fix: - vendor/bin/phpcbf - -.PHONY: static-analysis -static-analysis: - vendor/bin/phpstan analyse - -.PHONY: check -check: build lint cs static-analysis test - -### END - -### BEGIN cleaning - -.PHONY: clean -clean: clean-vendor - -.PHONY: clean-vendor -clean-vendor: - rm -rf vendor - -### END diff --git a/README.md b/README.md index 3821b80..6673449 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,6 @@ Based on Doctrine Coding Standard https://github.com/doctrine/coding-standard * Require this project as composer dev dependency: ``` -composer require --dev cdn77/coding-standard +composer require --dev exosuite/coding-standard ``` -* Reference this coding standard in your `phpcs.xml.dist` (_check out [the one used in this project](phpcs.xml.dist)_): -``` - -``` diff --git a/composer.json b/composer.json index ce789ad..c752ce5 100644 --- a/composer.json +++ b/composer.json @@ -1,30 +1,15 @@ { - "name": "cdn77/coding-standard", - "description": "Cdn77 Coding Standard.", - "type": "phpcodesniffer-standard", + "name": "exosuite/coding-standard", + "description": "ExoSuite Coding Standard.", "license": "MIT", "autoload": { "psr-4": { - "Cdn77CodingStandard\\": "src/Cdn77" - } - }, - "autoload-dev": { - "psr-4": { - "Cdn77CodingStandard\\Tests\\": "tests/" + "ExoSuiteCodingStandard\\": "ExoSuiteCodingStandard" } }, "require": { "php": "^7.1||^8.0", - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", - "doctrine/coding-standard": "^5.0", - "squizlabs/php_codesniffer": "^3.4.0" - }, - "require-dev": { - "jakub-onderka/php-parallel-lint": "^1.0", - "phpstan/phpstan": "^0.10.8", - "phpstan/phpstan-phpunit": "^0.10.0", - "phpstan/phpstan-strict-rules": "^0.10.1", - "phpunit/phpunit": "^7.0" + "squizlabs/php_codesniffer": "*" }, "config": { "sort-packages": true diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 2d8a711..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - src/ - tests/ - - tests/*/data/* - diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index 8a6b07e..0000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,13 +0,0 @@ -parameters: - bootstrap: %currentWorkingDirectory%/tests/bootstrap.php - memory-limit: -1 - level: max - excludes_analyse: - - %currentWorkingDirectory%/tests/*/data/* - - %currentWorkingDirectory%/vendor - paths: - - %currentWorkingDirectory% - -includes: - - vendor/phpstan/phpstan-phpunit/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 5cb7927..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,19 +0,0 @@ - - - - tests - - - - src/ - - - diff --git a/src/Cdn77/Sniffs/Classes/SingleLineMethodDeclarationWhenPossibleSniff.php b/src/Cdn77/Sniffs/Classes/SingleLineMethodDeclarationWhenPossibleSniff.php deleted file mode 100644 index 5e39045..0000000 --- a/src/Cdn77/Sniffs/Classes/SingleLineMethodDeclarationWhenPossibleSniff.php +++ /dev/null @@ -1,99 +0,0 @@ -getTokens(); - - $lineStartPtr = $file->findFirstOnLine(T_WHITESPACE, $pointer); - assert(is_int($lineStartPtr)); - - $methodDeclarationEndPtr = $file->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $pointer); - assert(is_int($methodDeclarationEndPtr)); - - $declarationEndLine = $tokens[$methodDeclarationEndPtr]['line']; - if (in_array($tokens[$lineStartPtr]['line'], [$declarationEndLine, $declarationEndLine - 1], true)) { - return; - } - - $methodDeclaration = TokenHelper::getContent($file, $lineStartPtr, $methodDeclarationEndPtr - 1); - $methodDeclaration = preg_replace('~\n +~', ' ', $methodDeclaration); - assert(is_string($methodDeclaration)); - - $methodDeclaration = str_replace(['( ', ' )'], ['(', ')'], $methodDeclaration); - $methodDeclaration = rtrim($methodDeclaration); - - if (strlen($methodDeclaration) > $this->maxLineLength) { - return; - } - - $error = sprintf('Method "%s" can be placed on a single line.', FunctionHelper::getName($file, $pointer)); - $fix = $file->addFixableError($error, $pointer, self::CODE_UNNECESSARY_MULTI_LINE_METHOD); - if (!$fix) { - return; - } - - $whitespaceBeforeMethod = $tokens[$lineStartPtr]['content']; - - $file->fixer->beginChangeset(); - - for ($i = $lineStartPtr; $i <= $methodDeclarationEndPtr; $i++) { - $file->fixer->replaceToken($i, ''); - } - - if ($tokens[$methodDeclarationEndPtr]['code'] === T_OPEN_CURLY_BRACKET) { - $replacement = sprintf("%s\n%s{", $methodDeclaration, $whitespaceBeforeMethod); - } else { - $replacement = $methodDeclaration . ';'; - } - - $file->fixer->replaceToken($lineStartPtr, $replacement); - - $file->fixer->endChangeset(); - } -} diff --git a/src/Cdn77/Sniffs/Files/LineLengthSniff.php b/src/Cdn77/Sniffs/Files/LineLengthSniff.php deleted file mode 100644 index 47cff6f..0000000 --- a/src/Cdn77/Sniffs/Files/LineLengthSniff.php +++ /dev/null @@ -1,142 +0,0 @@ -getTokens(); - for ($i = 0; $i < $file->numTokens; $i++) { - if ($tokens[$i]['column'] !== 1) { - continue; - } - - $this->checkLineLength($file, $tokens, $i); - } - - return $file->numTokens + 1; - } - - /** - * @param mixed[] $tokens - */ - private function checkLineLength(File $file, array $tokens, int $pointer) : void - { - if ($tokens[$pointer]['column'] === 1 && $tokens[$pointer]['length'] === 0) { - // Blank line. - return; - } - - $line = $tokens[$pointer]['line']; - $nextLineStartPtr = $pointer; - while (isset($tokens[$nextLineStartPtr]) && $line === $tokens[$nextLineStartPtr]['line']) { - $pointer = $nextLineStartPtr; - $nextLineStartPtr++; - } - - if ($tokens[$pointer]['content'] === $file->eolChar) { - $pointer--; - } - - $lineLength = $tokens[$pointer]['column'] + $tokens[$pointer]['length'] - 1; - if ($lineLength <= $this->lineLengthLimit) { - return; - } - - if (in_array($tokens[$pointer]['code'], [T_COMMENT, T_DOC_COMMENT_STRING], true)) { - if ($this->ignoreComments === true) { - return; - } - - // If this is a long comment, check if it can be broken up onto multiple lines. - // Some comments contain unbreakable strings like URLs and so it makes sense - // to ignore the line length in these cases if the URL would be longer than the max - // line length once you indent it to the correct level. - if ($lineLength > $this->lineLengthLimit) { - $oldLength = strlen($tokens[$pointer]['content']); - $newLength = strlen(ltrim($tokens[$pointer]['content'], "/#\t ")); - $indent = $tokens[$pointer]['column'] - 1 + $oldLength - $newLength; - - $nonBreakingLength = $tokens[$pointer]['length']; - - $space = strrpos($tokens[$pointer]['content'], ' '); - if ($space !== false) { - $nonBreakingLength -= ($space + 1); - } - - if ($nonBreakingLength + $indent > $this->lineLengthLimit) { - return; - } - } - } - - if ($this->ignoreImports) { - $usePointer = $file->findPrevious(T_USE, $pointer - 1); - if (is_int($usePointer) - && $tokens[$usePointer]['line'] === $tokens[$pointer]['line'] - && !UseStatementHelper::isTraitUse($file, $usePointer)) { - return; - } - } - - $error = 'Line exceeds maximum limit of %s characters; contains %s characters'; - $file->addError( - $error, - $pointer, - self::CODE_LINE_TOO_LONG, - [$this->lineLengthLimit, $lineLength] - ); - } -} diff --git a/src/Cdn77/ruleset.xml b/src/Cdn77/ruleset.xml deleted file mode 100644 index 7a25e4a..0000000 --- a/src/Cdn77/ruleset.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/Sniffs/Classes/ClassStructureSniffTest.php b/tests/Sniffs/Classes/ClassStructureSniffTest.php deleted file mode 100644 index 41d6358..0000000 --- a/tests/Sniffs/Classes/ClassStructureSniffTest.php +++ /dev/null @@ -1,106 +0,0 @@ - 0, - ClassStructureSniff::STAGE_USES => 10, - ClassStructureSniff::STAGE_PUBLIC_CONSTANTS => 20, - ClassStructureSniff::STAGE_PROTECTED_CONSTANTS => 20, - ClassStructureSniff::STAGE_PRIVATE_CONSTANTS => 20, - ClassStructureSniff::STAGE_PUBLIC_STATIC_PROPERTIES => 30, - ClassStructureSniff::STAGE_PROTECTED_STATIC_PROPERTIES => 30, - ClassStructureSniff::STAGE_PRIVATE_STATIC_PROPERTIES => 30, - ClassStructureSniff::STAGE_PUBLIC_STATIC_METHODS => 40, - ClassStructureSniff::STAGE_PROTECTED_STATIC_METHODS => 40, - ClassStructureSniff::STAGE_PRIVATE_STATIC_METHODS => 40, - ClassStructureSniff::STAGE_PUBLIC_PROPERTIES => 50, - ClassStructureSniff::STAGE_PROTECTED_PROPERTIES => 50, - ClassStructureSniff::STAGE_PRIVATE_PROPERTIES => 50, - ClassStructureSniff::STAGE_MAGIC_METHODS => 60, - ClassStructureSniff::STAGE_PUBLIC_METHODS => 70, - ClassStructureSniff::STAGE_PROTECTED_METHODS => 70, - ClassStructureSniff::STAGE_PRIVATE_METHODS => 70, - ClassStructureSniff::STAGE_CONSTRUCTOR => 80, - ClassStructureSniff::STAGE_STATIC_CONSTRUCTORS => 90, - ClassStructureSniff::STAGE_DESTRUCTOR => 100, - ]; - - public function testNoErrors() : void - { - self::assertNoSniffErrorInFile(self::checkFile(__DIR__ . '/data/ClassStructureSniffNoErrors.php')); - } - - public function testErrors() : void - { - $file = self::checkFile(__DIR__ . '/data/ClassStructureSniffErrors.php'); - - self::assertSame(23, $file->getErrorCount()); - - self::assertSniffError($file, 6, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 12, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 18, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 24, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 33, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 44, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 55, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 66, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 77, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 88, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 99, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 111, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 117, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 128, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 132, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 145, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 154, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 161, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 175, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 179, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 186, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - - self::assertAllFixedInFile($file); - } - - public function testNoErrorsWithDifferentRules() : void - { - $file = self::checkFile( - __DIR__ . '/data/ClassStructureSniffNoErrorsWithDifferentRules.php', - ['requiredOrder' => self::DIFFERENT_RULES] - ); - - self::assertNoSniffErrorInFile($file); - } - - public function testErrorsWithDifferentRules() : void - { - $file = self::checkFile( - __DIR__ . '/data/ClassStructureSniffErrorsWithDifferentRules.php', - ['requiredOrder' => self::DIFFERENT_RULES] - ); - - self::assertSame(13, $file->getErrorCount()); - - self::assertSniffError($file, 6, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 12, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 27, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 38, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 49, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 60, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 69, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 73, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 85, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 94, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 103, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - self::assertSniffError($file, 107, ClassStructureSniff::CODE_INVALID_MEMBER_PLACEMENT); - - self::assertAllFixedInFile($file); - } -} diff --git a/tests/Sniffs/Classes/SingleLineMethodDeclarationWhenPossibleSniffTest.php b/tests/Sniffs/Classes/SingleLineMethodDeclarationWhenPossibleSniffTest.php deleted file mode 100644 index 7c11824..0000000 --- a/tests/Sniffs/Classes/SingleLineMethodDeclarationWhenPossibleSniffTest.php +++ /dev/null @@ -1,31 +0,0 @@ -getErrorCount()); - - $code = SingleLineMethodDeclarationWhenPossibleSniff::CODE_UNNECESSARY_MULTI_LINE_METHOD; - self::assertSniffError($file, 5, $code); - self::assertSniffError($file, 11, $code); - self::assertSniffError($file, 20, $code); - self::assertSniffError($file, 25, $code); - - self::assertAllFixedInFile($file); - } -} diff --git a/tests/Sniffs/Classes/data/ClassStructureSniffErrors.fixed.php b/tests/Sniffs/Classes/data/ClassStructureSniffErrors.fixed.php deleted file mode 100644 index 0c8976f..0000000 --- a/tests/Sniffs/Classes/data/ClassStructureSniffErrors.fixed.php +++ /dev/null @@ -1,189 +0,0 @@ - false]); - - self::assertSame(7, $file->getErrorCount()); - - self::assertSniffError($file, 5, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 7, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 10, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 12, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 15, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 19, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 20, LineLengthSniff::CODE_LINE_TOO_LONG); - } - - public function testErrorsIgnoreComments() : void - { - $file = self::checkFile(__DIR__ . '/data/LineLengthSniffErrorsIgnoreComments.php', ['ignoreComments' => true]); - - self::assertSame(4, $file->getErrorCount()); - - self::assertSniffError($file, 7, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 12, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 15, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 20, LineLengthSniff::CODE_LINE_TOO_LONG); - } - - public function testErrorsIgnoreImports() : void - { - $file = self::checkFile(__DIR__ . '/data/LineLengthSniffErrorsIgnoreImports.php'); - - self::assertSame(7, $file->getErrorCount()); - - self::assertSniffError($file, 7, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 9, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 12, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 14, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 17, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 21, LineLengthSniff::CODE_LINE_TOO_LONG); - self::assertSniffError($file, 22, LineLengthSniff::CODE_LINE_TOO_LONG); - } -} diff --git a/tests/Sniffs/Files/data/LineLengthSniffErrors.php b/tests/Sniffs/Files/data/LineLengthSniffErrors.php deleted file mode 100644 index d5a6607..0000000 --- a/tests/Sniffs/Files/data/LineLengthSniffErrors.php +++ /dev/null @@ -1,20 +0,0 @@ -someMethodNameHereLoremIpsumDolorSitAmetConsecteturAdipiscingElitBonumIncolumisAciesMiseraCaecitasMateriamVeroRerum(); diff --git a/tests/Sniffs/Files/data/LineLengthSniffErrorsIgnoreComments.php b/tests/Sniffs/Files/data/LineLengthSniffErrorsIgnoreComments.php deleted file mode 100644 index 6dc7e3f..0000000 --- a/tests/Sniffs/Files/data/LineLengthSniffErrorsIgnoreComments.php +++ /dev/null @@ -1,20 +0,0 @@ -someMethodNameHereLoremIpsumDolorSitAmetConsecteturAdipiscingElitBonumIncolumisAciesMiseraCaecitasMateriamVeroRerum(); diff --git a/tests/Sniffs/Files/data/LineLengthSniffErrorsIgnoreImports.php b/tests/Sniffs/Files/data/LineLengthSniffErrorsIgnoreImports.php deleted file mode 100644 index 16eda95..0000000 --- a/tests/Sniffs/Files/data/LineLengthSniffErrorsIgnoreImports.php +++ /dev/null @@ -1,22 +0,0 @@ -someMethodNameHereLoremIpsumDolorSitAmetConsecteturAdipiscingElitBonumIncolumisAciesMiseraCaecitasMateriamVeroRerum(); diff --git a/tests/Sniffs/Files/data/LineLengthSniffNoErrors.php b/tests/Sniffs/Files/data/LineLengthSniffNoErrors.php deleted file mode 100644 index 5a3f242..0000000 --- a/tests/Sniffs/Files/data/LineLengthSniffNoErrors.php +++ /dev/null @@ -1,21 +0,0 @@ -someMethodNameHere(); diff --git a/tests/TestCase.php b/tests/TestCase.php deleted file mode 100644 index c4a10cb..0000000 --- a/tests/TestCase.php +++ /dev/null @@ -1,18 +0,0 @@ -