1
votes

I am using php code sniffer with smyfony 3.1.

Package Name:Squiz I am trying to run phpcs command in my symfony based project.

Command:

phpcs --standard=/c/xampp/php/pear/PHP/CodeSniffer/Standards/Squiz  src/MYBundle/Controller/MYController.php  

Command is working fine, In this controller/class i have declared some private variable and method name which is not used anywhere in the controller/class.

Ruleset

I have appended new rule in the ruleset.xml file and create new file under this directory [Sniffs\Rule\UnusedPrivateField] UnusedPrivateField.php

<rule name="UnusedPrivateField"
          since="0.2"
          message="Avoid unused private fields such as '{0}'."
          class="Sniffs\Rule\UnusedPrivateField"
          externalInfoUrl="http://phpmd.org/rules/unusedcode.html#unusedprivatefield"></rule>

Question: How to call "UnusedPrivateField.php" code from new rule set ?

1
The format of your rule tag looks unlike any PHPCS example one, so I'm not sure why you've written it like that. Is there a particular reason? Also, you don't actually need to include rule tags for sniff that exist under the Sniffs folder of a standard - PHPCS will import them automatically (use phpcs -vv to see how the ruleset is parsed). But you don't say under which Sniffs folder you put the sniff - is it under Squiz/Sniffs? You also seem to say you've got a 3-folder structure when PHPCS expects two (Sniffs/CategoryName/SniffName.php). I think I need more information to help. - Greg Sherwood

1 Answers

1
votes

You can use UnusedPrivateElementsSniff for this.

I use it for over a year and it works great.