diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 0000000..2520ce7 --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,34 @@ +name: "PHPCS" + +on: + push: + branches: + - master + - workflow + paths: + - "**.php" + - "ruleset.xml" + - ".github/workflows/phpcs.yml" + pull_request: + branches: + - master + +jobs: + phpcs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Log php version + run: php --version + + - name: Composer install + run: php composer.phar install + + - name: Run php code sniffer + run: vendor/bin/phpcs -v --standard=ruleset.xml custom-standards + + - name: Run php code sniffer on tests + run: vendor/bin/phpcs -v --standard=PSR12 tests diff --git a/.github/workflows/sniff-test.yml b/.github/workflows/sniff-test.yml new file mode 100644 index 0000000..8e72049 --- /dev/null +++ b/.github/workflows/sniff-test.yml @@ -0,0 +1,31 @@ +name: "SNIFF-TEST" + +on: + push: + branches: + - master + - workflow + paths: + - "**.php" + - "ruleset.xml" + - ".github/workflows/sniff-test.yml" + pull_request: + branches: + - master + +jobs: + sniff-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Log php version + run: php --version + + - name: Composer install + run: php composer.phar install + + - name: Run php code sniffer tests + run: php tests/runner.php diff --git a/composer.phar b/composer.phar index b88fb5f..f6df0ce 100644 Binary files a/composer.phar and b/composer.phar differ diff --git a/custom-standards/Flyeralarm/Sniffs/Classes/FullyQualifiedSniff.php b/custom-standards/Flyeralarm/Sniffs/Classes/FullyQualifiedSniff.php index 2e8a703..8a47512 100644 --- a/custom-standards/Flyeralarm/Sniffs/Classes/FullyQualifiedSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/Classes/FullyQualifiedSniff.php @@ -13,13 +13,12 @@ class FullyQualifiedSniff implements Sniff */ public function register() { - return array(T_DOUBLE_COLON, T_NEW); + return [T_DOUBLE_COLON, T_NEW]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) { diff --git a/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php b/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php index 3f0cf28..6bf3228 100644 --- a/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php @@ -12,13 +12,12 @@ class YodaSniff implements Sniff */ public function register() { - return array(T_IF, T_ELSEIF, T_WHILE); + return [T_IF, T_ELSEIF, T_WHILE]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) { @@ -87,21 +86,25 @@ private function checkConditionalOrderForArithmeticExpression( // e.g. if ($foo = true) // e.g. if ($foo = 'bar') - if (in_array($leftOperandTokenId, $functionAndVariableTokenIds) + if ( + in_array($leftOperandTokenId, $functionAndVariableTokenIds) && in_array($rightOperandTokenId, $languageTypeTokenIds) ) { return; } // e.g. if (count(..) > $test) // e.g. if ($foo == $bar) - if (in_array($leftOperandTokenId, $functionAndVariableTokenIds) + if ( + in_array($leftOperandTokenId, $functionAndVariableTokenIds) && in_array($rightOperandTokenId, $functionAndVariableTokenIds) ) { return; } // e.g. if ('foo' == 'bar') - if (in_array($leftOperandTokenId, $languageTypeTokenIds) - && in_array($rightOperandTokenId, $languageTypeTokenIds)) { + if ( + in_array($leftOperandTokenId, $languageTypeTokenIds) + && in_array($rightOperandTokenId, $languageTypeTokenIds) + ) { return; } diff --git a/custom-standards/Flyeralarm/Sniffs/Docblock/ExpectedExceptionMessageSniff.php b/custom-standards/Flyeralarm/Sniffs/Docblock/ExpectedExceptionMessageSniff.php index 1c5ca32..042700a 100644 --- a/custom-standards/Flyeralarm/Sniffs/Docblock/ExpectedExceptionMessageSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/Docblock/ExpectedExceptionMessageSniff.php @@ -12,21 +12,22 @@ class ExpectedExceptionMessageSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_OPEN_TAG); + return [T_DOC_COMMENT_OPEN_TAG]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) { if (!$this->hasAnnotationInDoc($phpcsFile, $stackPtr, '@expectedException')) { return; } - if ($this->hasAnnotationInDoc($phpcsFile, $stackPtr, '@expectedExceptionMessage') - || $this->hasAnnotationInDoc($phpcsFile, $stackPtr, '@expectedExceptionMessageRegExp')) { + if ( + $this->hasAnnotationInDoc($phpcsFile, $stackPtr, '@expectedExceptionMessage') + || $this->hasAnnotationInDoc($phpcsFile, $stackPtr, '@expectedExceptionMessageRegExp') + ) { return; } diff --git a/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php b/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php index 6271637..5d58198 100644 --- a/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php @@ -41,13 +41,12 @@ class ReturnTypeSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_OPEN_TAG); + return [T_DOC_COMMENT_OPEN_TAG]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) { diff --git a/custom-standards/Flyeralarm/Sniffs/File/ExceptionMessageSniff.php b/custom-standards/Flyeralarm/Sniffs/File/ExceptionMessageSniff.php index a8193d7..5df674d 100644 --- a/custom-standards/Flyeralarm/Sniffs/File/ExceptionMessageSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/File/ExceptionMessageSniff.php @@ -12,13 +12,12 @@ class ExceptionMessageSniff implements Sniff */ public function register() { - return array(T_CLASS); + return [T_CLASS]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return int|void * @throws \PHP_CodeSniffer\Exceptions\RuntimeException */ public function process(File $phpcsFile, $stackPtr) @@ -31,7 +30,7 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $ptr = -1; - while($ptr = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $ptr + 1)) { + while ($ptr = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $ptr + 1)) { if (strpos($tokens[$ptr]['content'], '!') !== false) { $phpcsFile->addError( 'Exclamationmarks are not allowed in Exceptionmessages', diff --git a/custom-standards/Flyeralarm/Sniffs/File/ForbiddenKeywordsSniff.php b/custom-standards/Flyeralarm/Sniffs/File/ForbiddenKeywordsSniff.php index efbf0c5..c0b189d 100644 --- a/custom-standards/Flyeralarm/Sniffs/File/ForbiddenKeywordsSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/File/ForbiddenKeywordsSniff.php @@ -12,13 +12,12 @@ class ForbiddenKeywordsSniff implements Sniff */ public function register() { - return array(T_CLASS, T_ABSTRACT, T_TRAIT); + return [T_CLASS, T_ABSTRACT, T_TRAIT]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) { diff --git a/custom-standards/Flyeralarm/Sniffs/File/NamespacesSniff.php b/custom-standards/Flyeralarm/Sniffs/File/NamespacesSniff.php index 01cd9a1..49803b5 100644 --- a/custom-standards/Flyeralarm/Sniffs/File/NamespacesSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/File/NamespacesSniff.php @@ -12,19 +12,18 @@ class NamespacesSniff implements Sniff */ public function register() { - return array(T_CLASS, T_ABSTRACT, T_TRAIT, T_INTERFACE); + return [T_CLASS, T_ABSTRACT, T_TRAIT, T_INTERFACE]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $ptr = -1; - while($ptr = $phpcsFile->findNext(T_NS_SEPARATOR, $ptr + 1)) { + while ($ptr = $phpcsFile->findNext(T_NS_SEPARATOR, $ptr + 1)) { if (strpos($tokens[$ptr + 1]['content'], '_') !== false) { $phpcsFile->addError( 'Using underscore within namespaces is discouraged', diff --git a/custom-standards/Flyeralarm/Sniffs/File/NoClassKindSuffixSniff.php b/custom-standards/Flyeralarm/Sniffs/File/NoClassKindSuffixSniff.php index 0e98b85..9a27c6e 100644 --- a/custom-standards/Flyeralarm/Sniffs/File/NoClassKindSuffixSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/File/NoClassKindSuffixSniff.php @@ -12,13 +12,12 @@ class NoClassKindSuffixSniff implements Sniff */ public function register() { - return array(T_INTERFACE, T_CLASS, T_TRAIT); + return [T_INTERFACE, T_CLASS, T_TRAIT]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return int|void * @throws \PHP_CodeSniffer\Exceptions\RuntimeException */ public function process(File $phpcsFile, $stackPtr) diff --git a/custom-standards/Flyeralarm/Sniffs/Variable/LowerCamelCaseSniff.php b/custom-standards/Flyeralarm/Sniffs/Variable/LowerCamelCaseSniff.php index 46d016b..7e63c04 100644 --- a/custom-standards/Flyeralarm/Sniffs/Variable/LowerCamelCaseSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/Variable/LowerCamelCaseSniff.php @@ -28,13 +28,12 @@ class LowerCamelCaseSniff implements Sniff */ public function register() { - return array(T_OPEN_TAG); + return [T_OPEN_TAG]; } /** * @param File $phpcsFile * @param int $stackPtr - * @return void */ public function process(File $phpcsFile, $stackPtr) {