The method __constructor can be private, but at the same time it it is never called in the current class. So, we should skip it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

LOBsTerr created an issue. See original summary.

LOBsTerr’s picture

Status: Active » Needs review
FileSize
763 bytes
klausi’s picture

Title: Unused private method __construct() » Allow private method __construct() in UnusedPrivateMethodSniff
Status: Needs review » Needs work
Issue tags: +Needs tests

I see, you would use a private __construct() if you don't want anybody to instantiate your class. So you probably only want it to be used for static methods or constants.

The patch makes sense, can you add a test case in UnusedPrivateMethodUnitTest.inc?

Please also create a pull request against https://github.com/pfrenssen/coder , then we see the automated tests run.

LOBsTerr’s picture

I have added a test case and created PR https://github.com/pfrenssen/coder/pull/58

LOBsTerr’s picture

Status: Needs work » Needs review
FileSize
1.87 KB
666 bytes

A small fix change == to ===

  • klausi committed 2a4dbff on 8.x-3.x
    fix(UnusedPrivateMethod): Allow private constructor methods (#3079227)
    
    
klausi’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Thank you so much, committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.