Skip to content
Closed
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
34 changes: 34 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions .github/workflows/sniff-test.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file modified composer.phar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions custom-standards/Flyeralarm/Sniffs/File/NamespacesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down