Skip to content

Create Abstract_Check_Runner class #63

@jjgrainger

Description

@jjgrainger

Description

The Abstract_Check_Runner class will contain common logic used to run Checks across both CLI and AJAX. The abstract class will be used to build out the following runner classes:

Acceptance Criteria

  • A new Abstract_Check_Runner class will exist in includes/Checker.
  • The class will implement the Check_Runner interface.
  • The class has a protected $checks property.
  • The class has a protected $checks_to_run property.
  • The class has an abstract is_plugin_check() method.
  • The class has an abstract protected setup_checks() method.
  • The class contains a prepare() method.
    • The prepare() method accepts no parameters.
    • The prepare() method is used to run any universal preparations early in the WordPress load.
      • The array of $checks_to_run array is passed to the requires_universal_preparations() method (Create Abstract_Check_Runner class #63).
      • If the method returns true the Universal_Runtime_Preparation will be used.
      • The prepare method will instantiate the Universal_Runtime_Preparation (Create a Universal_Runtime_Preparation #61) and call the prepare() method.
      • The cleanup function returned by the prepare() method is then returned.
  • The class has a protected requires_universal_preparations( array $checks ) method.
    • The method accepts an array of Check instances that will be run.
    • The method loops over the Check instances and tests to see if any Checks implement the Runtime_Check interface.
    • If any Check implements the Runtime_Check interface, the method returns true, if not, the method returns false.
  • The class implements a private get_shared_preparations( array $checks ) method.
    • The method accepts an array of Check instances that will be run.
    • The method assigns an empty array to a $preparations variable.
    • The method loops of the Check instants and tests for Checks that implement the With_Shared_Preparations interface.
    • If the Check implements the With_Shared_Preparations interface, the Checks get_shared_preparations method is called to return an array of preparations.
    • The preparations returned are checked for any duplicates by evaluating the preparation name and the array of constructor arguments to see if these match any existing shared preparations in the $preparations array.
    • These preparations are merged into the $preparations variable and returned by the method.
  • The class implements the run() method.
    • The run method will gather the Check instances from $this->checks->get_checks() using the requested checks in the $checks_to_run property.
    • The get_shared_preparations is called passing the $checks_to_run array. The returned shared preparations are then looped over calling each preparations prepare() method. The preparations cleanup functions are then stored to a $cleanups variable.
    • The Checks are then run by passing the $checks_to_run array is then passed to $this->checks->run_checks() and the Check_Results instanced returned stored as a variable.
    • If the get_shared_preparations preparations where prepared the $cleanups functions returned are called.
    • The run method returns the $check_results instance.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions