Skip to content

Create abstract class PHP_CodeSniffer_Check #8

@mehulkaklotar

Description

@mehulkaklotar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    InfrastructureIssues for the overall plugin infrastructure[Type] EnhancementA suggestion for improvement of an existing feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions