Skip to content

Commit d555296

Browse files
Merge pull request #36 from flyeralarm/FixKeyForYodaSniff
Fix key for yoda sniff
2 parents c25d205 + 548287d commit d555296

File tree

6 files changed

+70
-21
lines changed

6 files changed

+70
-21
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.php text eol=lf
2+
*.xml text eol=lf

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PHP_IMAGE_TAG=flyeralarm/php-code-valiator-cli:$(PHP_VERSION)
2-
PHP_VERSION?=8.2
2+
PHP_VERSION?=8.3
33

44
PHP_BIN=$(RUNNER) php
55
COMPOSER_BIN=$(RUNNER) /usr/bin/composer
@@ -40,6 +40,7 @@ test:
4040

4141
.PHONY: test-all
4242
test-all:
43+
PHP_VERSION=8.3 $(MAKE) build update sniff test
4344
PHP_VERSION=8.2 $(MAKE) build update sniff test
4445
PHP_VERSION=8.1 $(MAKE) build update sniff test
4546
PHP_VERSION=7.4 $(MAKE) build update sniff test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interpreted as described in [RFC 2119](http://www.ietf.org/rfc/rfc2119.txt).
2323

2424
To prepare run command:
2525
```bash
26+
make build
2627
make install
2728
```
2829

composer.lock

Lines changed: 41 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

custom-standards/Flyeralarm/Sniffs/ControlStructures/YodaSniff.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Flyeralarm\CodingGuidelines\Flyeralarm\Sniffs\ControlStructures;
44

5-
use PHP_CodeSniffer\Sniffs\Sniff;
65
use PHP_CodeSniffer\Files\File;
6+
use PHP_CodeSniffer\Sniffs\Sniff;
77

88
class YodaSniff implements Sniff
99
{
@@ -15,6 +15,7 @@ public function register()
1515
return [T_IF, T_ELSEIF, T_WHILE];
1616
}
1717

18+
1819
/**
1920
* @param File $phpcsFile
2021
* @param int $stackPtr
@@ -25,7 +26,7 @@ public function process(File $phpcsFile, $stackPtr)
2526
$tokens = $phpcsFile->getTokens();
2627

2728
$startOfConditionPtr = $stackPtr;
28-
$endPtr = $tokens[$startOfConditionPtr]['scope_opener'] + 1;
29+
$endPtr = $this->getConditionStartPointerDoWhileStable($tokens[$startOfConditionPtr]);
2930

3031
$logicalOperatorTokenIds = [T_BOOLEAN_AND, T_BOOLEAN_OR, T_LOGICAL_AND, T_LOGICAL_OR, T_LOGICAL_XOR];
3132
$scopeOpenerTokenIds = [T_OPEN_CURLY_BRACKET];
@@ -37,6 +38,7 @@ public function process(File $phpcsFile, $stackPtr)
3738
}
3839
}
3940

41+
4042
/**
4143
* @param File $phpcsFile
4244
* @param $startOfConditionPtr
@@ -115,4 +117,14 @@ private function checkConditionalOrderForArithmeticExpression(
115117
'ConditionalOrder'
116118
);
117119
}
120+
121+
122+
private function getConditionStartPointerDoWhileStable(array $array): ?int
123+
{
124+
if (array_key_exists('scope_opener', $array)) {
125+
return $array['scope_opener'] + 1;
126+
}
127+
128+
return null;
129+
}
118130
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// @expectedPass
4+
5+
namespace Flyeralarm\CodingGuidelines;
6+
7+
$i = 0;
8+
do {
9+
echo $i;
10+
} while ($i > 0);

0 commit comments

Comments
 (0)