Skip to content

Commit 9dd9738

Browse files
committed
UnusedPrivateElementsSniff - do not report private constructor
1 parent 46cd765 commit 9dd9738

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

SlevomatCodingStandard/Sniffs/Classes/UnusedPrivateElementsSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ private function getMethods(PHP_CodeSniffer_File $phpcsFile, array $tokens, arra
243243
continue;
244244
}
245245

246-
$reportedMethods[$tokens[$namePointer]['content']] = $methodTokenPointer;
246+
$methodName = $tokens[$namePointer]['content'];
247+
248+
if ($methodName !== '__construct') {
249+
$reportedMethods[$methodName] = $methodTokenPointer;
250+
}
247251
$findMethodsStartTokenPointer = $methodTokenPointer + 1;
248252
}
249253

tests/Sniffs/Classes/UnusedPrivateElementsSniffTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function testCheckFile()
4848
UnusedPrivateElementsSniff::CODE_UNUSED_METHOD,
4949
'Class ClassWithSomeUnusedProperties contains unused private method: unusedStaticPrivateMethod'
5050
);
51+
$this->assertNoSniffError($resultFile, 70);
5152
}
5253

5354
}

tests/Sniffs/Classes/data/ClassWithSomeUnusedProperties.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ private static function unusedStaticPrivateMethod()
6767

6868
}
6969

70+
private function __construct()
71+
{
72+
73+
}
74+
7075
}

0 commit comments

Comments
 (0)