2

I know PHP CS Fixer and Psalm to lint PHP. I've been using both of them. But I can't find a way to lint / validate my namespace name based on the folder.

For example, in folder Tests/Controllers/V1, I have MyControllerTest.php, and it has the following codes:

<?php

// I should have correct namespace based on folder name not V2 but V1
namespace Tests\Controllers\V2;


.. ... my code

How can I lint the above code with correct namespace?

NOTE: I am using PHP 7.3.

rhzs
  • 516
  • 7
  • 24
  • using backlash Tests\Controllers\V2 – Jerson Oct 03 '20 at 10:57
  • @Jerson yap updated, any idea how to lint the namespace? – rhzs Oct 03 '20 at 13:33
  • As far as I am aware it's not a PHP coding violation to have namespace mismatching folder names, and it's not the job of a linter to find those mistakes either. Sorry but I don't think anyone is going to be able to give you an answer that satisfies your criteria. If it was me, and I had to catch these mistakes, I'd probably write a python or bash script to do such checks. – Kodaloid Oct 03 '20 at 19:27
  • @Kodaloid, all rules in PHP CS Fixer / Psalm are not PHP coding violation neither. It's just rules for better code and spot common mistakes. And I need Namespace check rule. – rhzs Oct 04 '20 at 12:51

0 Answers0