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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.php text eol=lf
*.xml text eol=lf
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
53 changes: 38 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -15,6 +15,7 @@ public function register()
return [T_IF, T_ELSEIF, T_WHILE];
}


/**
* @param File $phpcsFile
* @param int $stackPtr
Expand All @@ -25,7 +26,9 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();

$startOfConditionPtr = $stackPtr;
$endPtr = $tokens[$startOfConditionPtr]['scope_opener'] + 1;
if (array_key_exists('scope_opener', $tokens[$startOfConditionPtr])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test-case for this?

$endPtr = $tokens[$startOfConditionPtr]['scope_opener'] + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$endPtr should always be initialized.

}

$logicalOperatorTokenIds = [T_BOOLEAN_AND, T_BOOLEAN_OR, T_LOGICAL_AND, T_LOGICAL_OR, T_LOGICAL_XOR];
$scopeOpenerTokenIds = [T_OPEN_CURLY_BRACKET];
Expand All @@ -37,6 +40,7 @@ public function process(File $phpcsFile, $stackPtr)
}
}


/**
* @param File $phpcsFile
* @param $startOfConditionPtr
Expand Down