Commit 2a4dbff9 authored by Nikolay Lobachev's avatar Nikolay Lobachev Committed by Klaus Purer
Browse files

fix(UnusedPrivateMethod): Allow private constructor methods (#3079227)

parent c8664dfc
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@ class UnusedPrivateMethodSniff extends AbstractScopeSniff
        $tokens     = $phpcsFile->getTokens();
        $methodName = $phpcsFile->getDeclarationName($stackPtr);

        if ($methodName === '__construct') {
            return;
        }

        $classPtr = key($tokens[$stackPtr]['conditions']);

        // Search for direct $this->methodCall() or indirect callbacks [$this,
+7 −0
Original line number Diff line number Diff line
@@ -2,6 +2,13 @@

class Test {

  /**
   * Private constructor in case class can be instantiated.
   */
  private function __construct() {

  }

  /**
   * Method is not called from anywhere in the class.
   */
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ class UnusedPrivateMethodUnitTest extends CoderSniffUnitTest
     */
    protected function getWarningList()
    {
        return [8 => 1];
        return [15 => 1];

    }//end getWarningList()