0

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.

  1. Which standards should I prioritize?
  2. Should I configurate PHPMD to ignore symfony and its dependencies coding structure?
  3. 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>
Ignas Damunskis
  • 1,515
  • 1
  • 17
  • 44
  • [PHP Reddit](https://www.reddit.com/r/PHP/) might be a better fit for this sort of question. Having guidelines is useful but they should not dictate your code. I suspect there are plenty of developers who feel having even 10 public methods is a red flag. You certainly can't have too many tests as long as they actually test something. You could move your finder methods into their own classes and just inject the repository. But as long as you feel the code is maintainable then why bother. – Cerad Sep 25 '22 at 12:49

0 Answers0