Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PageSpeed | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| run | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Migration\Steps; |
| 4 | |
| 5 | use NewfoldLabs\WP\Module\Migration\Steps\AbstractStep; |
| 6 | use NewfoldLabs\WP\Module\Migration\Services\PageSpeedService; |
| 7 | |
| 8 | /** |
| 9 | * Get Speed Index by PageSpeed api for url. |
| 10 | * |
| 11 | * @package wp-module-migration |
| 12 | */ |
| 13 | class PageSpeed extends AbstractStep { |
| 14 | /** |
| 15 | * URL to get speed index. |
| 16 | * |
| 17 | * @var string $url |
| 18 | */ |
| 19 | protected $url = ''; |
| 20 | /** |
| 21 | * Construct. Init basic parameters. |
| 22 | * |
| 23 | * @param string $url url to get speed index. |
| 24 | * @param string $type type of the step. |
| 25 | */ |
| 26 | public function __construct( $url, $type = 'source' ) { |
| 27 | $step_slug = 'PageSpeed_' . $type; |
| 28 | $this->set_step_slug( $step_slug ); |
| 29 | $this->set_max_retries( 2 ); |
| 30 | $this->url = $url; |
| 31 | $this->set_status( $this->statuses['running'] ); |
| 32 | $this->run(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Execute the step. |
| 37 | * |
| 38 | * @return void |
| 39 | */ |
| 40 | protected function run() { |
| 41 | $pagespeed_service = new PageSpeedService( $this->url ); |
| 42 | $pagespeed = $pagespeed_service->get_pagespeed(); |
| 43 | $this->set_data( 'url', $this->url ); |
| 44 | if ( isset( $pagespeed['speedIndex'] ) ) { |
| 45 | $this->set_data( 'speedIndex', $pagespeed['speedIndex'] ); |
| 46 | $this->success(); |
| 47 | } else { |
| 48 | $this->set_response( |
| 49 | array( |
| 50 | 'message' => $pagespeed['message'], |
| 51 | ) |
| 52 | ); |
| 53 | $this->retry(); |
| 54 | |
| 55 | } |
| 56 | } |
| 57 | } |