Skip to content
Merged
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
59 changes: 41 additions & 18 deletions composer.lock

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

16 changes: 14 additions & 2 deletions custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php
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,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];
Expand All @@ -37,6 +38,7 @@ public function process(File $phpcsFile, $stackPtr)
}
}


/**
* @param File $phpcsFile
* @param $startOfConditionPtr
Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions tests/rules/control-structures/yoda/allowed/DoWhile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// @expectedPass

namespace Flyeralarm\CodingGuidelines;

$i = 0;
do {
echo $i;
} while ($i > 0);
Loading