This abstract class will be used to create concrete check classes that perform static analysis. This class will provide foundational methods that allow concrete classes to define code standards and sniffs to test the plugin code against. It will also contain an instance of PHP_CodeSniffer\Runner to run the tests and return the results to be processed.
Acceptance Criteria
- An abstract
Abstract_PHP_CodeSniffer_Check class exists
- The
Abstract_PHP_CodeSniffer_Check implements the Check interface
- The class contains a
public function run( Check_Result $result ) method
- The
run() method accepts a single $result parameter
- The
$result parameter is an instance of the Check_Result class
- The
run() method handles the logic to
- Require in the PHPCS autoloader from composer vendor folder
- Backup the original
$_SERVER['argv'] array to a $original_cmd_args variable
- Generate the arguments to pass to PHPCS by passing
$result->plugin() to Abstract_PHP_CodeSniffer_Check::get_args() method
- Set the
$_SERVER['argv'] array to the arguments to pass to PHPCS
- Run PHPCS using an instance of
\PHP_CodeSniffer\Runner class
- Restore the original command arguments from
$original_cmd_args variable
- Add the results from PHPCS to the
$results object using the $results->add_message() method
- The
Abstract_PHP_CodeSniffer_Check contains a abstract function get_args( Check_Context $context ) method
- The
get_args() method accepts a $context parameter
- The
$context parameter is an instance of Check_Context
- The
get_args() method will be written in concrete Check classes to return the arguments to pass to PHPCS
This abstract class will be used to create concrete check classes that perform static analysis. This class will provide foundational methods that allow concrete classes to define code standards and sniffs to test the plugin code against. It will also contain an instance of
PHP_CodeSniffer\Runnerto run the tests and return the results to be processed.Acceptance Criteria
Abstract_PHP_CodeSniffer_Checkclass existsAbstract_PHP_CodeSniffer_Checkimplements theCheckinterfacepublic function run( Check_Result $result )methodrun()method accepts a single$resultparameter$resultparameter is an instance of theCheck_Resultclassrun()method handles the logic to$_SERVER['argv']array to a$original_cmd_argsvariable$result->plugin()toAbstract_PHP_CodeSniffer_Check::get_args()method$_SERVER['argv']array to the arguments to pass to PHPCS\PHP_CodeSniffer\Runnerclass$original_cmd_argsvariable$resultsobject using the$results->add_message()methodAbstract_PHP_CodeSniffer_Checkcontains aabstract function get_args( Check_Context $context )methodget_args()method accepts a$contextparameter$contextparameter is an instance ofCheck_Contextget_args()method will be written in concrete Check classes to return the arguments to pass to PHPCS