I'm working on a Magento 2 CRUD functionality following the best practices (best described here). On the project I'm working on we are using PHPMD (php mess detector). Among other rules, we have the CBO limit set to 13 (which I understand is the default). My repository is implementing the get, save, getList, delete, deleteById methods and the limit is already 12.

What would be best practice if I need to add other methods to this repository without overlapping the PHPMD CBO limit? Should I break the repository in multiple ones? If so how would a directory and file naming and structure would look?

P.S. I understand that helper classes are no longer encouraged in Magento 2.

  • Magento by it's very nature is repetitive. Whilst I appreciate the merits of scanning code with phpmd you will struggle to get anything done. You are best sticking with m2 phpcs ruleset magento.stackexchange.com/a/277385/70343 Jun 5, 2019 at 19:37
  • yeah, I totally understand, but some times you don't get to chose the tools :( - should I also add SonarQube into the mix? you will then get restrictions such as number of dependencies you can inject in a constructor class which kinda kills the composition over inheritance principle. I'm trying to understand if there are ways to overcome this kind of situations and also follow best practices.
    – Radu
    Jun 5, 2019 at 19:48
  • Oh no way! :( Yep magento relies heavily on this too. Sorry I can't help more Jun 5, 2019 at 19:55


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.