Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Scan | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| setup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fetch | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| evaluate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Onboarding\Compatibility; |
| 4 | |
| 5 | /** |
| 6 | * Class Scan |
| 7 | */ |
| 8 | class Scan { |
| 9 | |
| 10 | /** |
| 11 | * Configuration defaults. |
| 12 | * |
| 13 | * @var array |
| 14 | */ |
| 15 | public $default_config = array( |
| 16 | 'min_wp' => '6.5', |
| 17 | ); |
| 18 | |
| 19 | /** |
| 20 | * Environment data. |
| 21 | * |
| 22 | * @var array |
| 23 | */ |
| 24 | public $data = array( |
| 25 | 'wp_version' => '', |
| 26 | ); |
| 27 | |
| 28 | /** |
| 29 | * Active Configuration. |
| 30 | * |
| 31 | * @var array |
| 32 | */ |
| 33 | public $config = array(); |
| 34 | |
| 35 | /** |
| 36 | * Test statuses. |
| 37 | * |
| 38 | * @var array |
| 39 | */ |
| 40 | public $test_statuses = array( |
| 41 | 'compatible', |
| 42 | 'unsupported-wp', |
| 43 | ); |
| 44 | |
| 45 | /** |
| 46 | * Result of the compatibility scan. |
| 47 | * |
| 48 | * @var string |
| 49 | */ |
| 50 | public $result = ''; |
| 51 | |
| 52 | /** |
| 53 | * Scan constructor. |
| 54 | * |
| 55 | * @param array $config Config data. |
| 56 | */ |
| 57 | public function __construct( $config = array() ) { |
| 58 | $this->setup( $config ); |
| 59 | // Fetch Relevant Data |
| 60 | $this->fetch(); |
| 61 | // Evaluate Using Configuration & Data |
| 62 | $this->evaluate(); |
| 63 | |
| 64 | return array( |
| 65 | 'status' => $this->result, |
| 66 | 'data' => $this->data, |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Register configuration. |
| 72 | * |
| 73 | * @param array $config Config data. |
| 74 | */ |
| 75 | protected function setup( $config ) { |
| 76 | $this->config = array_merge( $this->default_config, $config ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Set up environment data to be checked. |
| 81 | */ |
| 82 | protected function fetch() { |
| 83 | global $wp_version; |
| 84 | |
| 85 | $this->data = array_merge( |
| 86 | $this->data, |
| 87 | array( |
| 88 | 'wp_version' => $wp_version, |
| 89 | ) |
| 90 | ); |
| 91 | |
| 92 | $previous = Status::get(); |
| 93 | if ( ! empty( $previous ) && is_array( $previous ) ) { |
| 94 | $this->data['previous_result'] = $previous; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Run the compatibility check. |
| 100 | */ |
| 101 | protected function evaluate() { |
| 102 | |
| 103 | $this->result = 'scan-initiated'; |
| 104 | |
| 105 | if ( version_compare( $this->data['wp_version'], $this->config['min_wp'], '<' ) ) { |
| 106 | $this->result = 'unsupported-wp'; |
| 107 | } |
| 108 | |
| 109 | if ( 'scan-initiated' === $this->result ) { |
| 110 | $this->result = 'compatible'; |
| 111 | } |
| 112 | } |
| 113 | } |