I have created a huge symfony application with many entity and their repository classes. Some of these repository classes contain more than 10 public methods named as findAppointmentCount
, findReports
, etc. where I keep my queries to database.
I also created many phpunit tests for my Doctrine ORM entity classes that have more than 10 public getter and setter methods. These getter/setter methods not only get/set entity property, but has some extra logic within, so writing tests seems like a no-brainer. As recommended by phpunit docs, if I test setToken
method I would create a testSettingToken
etc.
Since I am following doctrine and phpunit recommended structure, unfortunately, I get multiple PHPMD TooManyPublicMethods
errors such as:
TooManyPublicMethods The class AppointmentRepository has 11 public methods. Consider refactoring AppointmentRepository to keep number of public methods under 10.
TooManyPublicMethods The class AppointmentTest has 15 public methods. Consider refactoring AppointmentTest to keep number of public methods under 10.
By default, PHPMD ignores methods that start with get|set
, but counts in find|test
prefixes.
- Which standards should I prioritize?
- Should I configurate PHPMD to ignore symfony and its dependencies coding structure?
- Should I strictly follow PHPMD coding standards and somehow adjust doctrine repositories and phpunit tests?
P.S. I know that it is possible to ignore test|find
prefixes by configuring PHPMD, but I need to know if thats the best practice.
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
<properties>
<property name="ignorepattern" value="(^(set|get|is|has|test|find))i"/>
</properties>
</rule>