Skip to content

Commit 4123364

Browse files
committed
Allow few core names in NoAccessorsSniff
1 parent 6ff314d commit 4123364

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Inpsyde/Sniffs/CodeQuality/NoAccessorsSniff.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
*/
2626
final class NoAccessorsSniff implements Sniff
2727
{
28-
public $allowSetUp = true;
28+
const ALLOWED_NAMES = [
29+
'getIterator',
30+
'getInnerIterator',
31+
'getChildren',
32+
'setUp',
33+
];
2934

3035
public $skipForFunctions = true;
3136

@@ -50,7 +55,7 @@ public function process(File $file, $position)
5055

5156
$functionName = $file->getDeclarationName($position);
5257

53-
if (!$functionName || ($functionName === 'setUp' && $this->allowSetUp)) {
58+
if (!$functionName || in_array($functionName, self::ALLOWED_NAMES, true)) {
5459
return;
5560
}
5661

tests/fixtures/no-accessors.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function setTheThing($foo, $bar);
2121
function setting();
2222
}
2323

24-
class WithAccessors {
24+
class WithAccessors implements \IteratorAggregate {
2525

2626
function thing() {
2727

@@ -44,4 +44,12 @@ function withThing() {
4444
function setTheThing($foo, $bar) {
4545

4646
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function getIterator()
52+
{
53+
return new \ArrayIterator();
54+
}
4755
}

0 commit comments

Comments
 (0)