WPSEO_GSC_Issue

Class WPSEO_GSC_Issue.

Defined (1)

The class is defined in the following location(s).

/admin/google_search_console/class-gsc-issue.php  
  1. class WPSEO_GSC_Issue { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $url; 
  7.  
  8. /** 
  9. * @var DateTime 
  10. */ 
  11. private $first_detected; 
  12.  
  13. /** 
  14. * @var DateTime 
  15. */ 
  16. private $last_crawled; 
  17.  
  18. /** 
  19. * @var string 
  20. */ 
  21. private $response_code; 
  22.  
  23. /** 
  24. * Search Console issue class constructor. 
  25. * @param string $url URL of the issue. 
  26. * @param DateTime $first_detected Time of first discovery. 
  27. * @param DateTime $last_crawled Time of last crawl. 
  28. * @param string $response_code HTTP response code. 
  29. */ 
  30. public function __construct( $url, DateTime $first_detected, DateTime $last_crawled, $response_code ) { 
  31. $this->url = $url; 
  32. $this->first_detected = $first_detected; 
  33. $this->last_crawled = $last_crawled; 
  34. $this->response_code = $response_code; 
  35.  
  36. /** 
  37. * Put the class properties in array 
  38. * @return array 
  39. */ 
  40. public function to_array() { 
  41. return array( 
  42. 'url' => $this->url,  
  43. 'first_detected' => $this->to_date_format( $this->first_detected ),  
  44. 'first_detected_raw' => $this->to_timestamp( $this->first_detected ),  
  45. 'last_crawled' => $this->to_date_format( $this->last_crawled ),  
  46. 'last_crawled_raw' => $this->to_timestamp( $this->last_crawled ),  
  47. 'response_code' => $this->response_code,  
  48. ); 
  49.  
  50. /** 
  51. * Converting the date to a date format 
  52. * @param DateTime $date_to_convert Date instance. 
  53. * @param string $format Format string. 
  54. * @return string 
  55. */ 
  56. private function to_date_format( DateTime $date_to_convert, $format = '' ) { 
  57.  
  58. if ( empty( $format ) ) { 
  59. $format = get_option( 'date_format' ); 
  60.  
  61. return date_i18n( $format, $date_to_convert->format( 'U' ) ); 
  62.  
  63. /** 
  64. * Converting the date to a timestamp 
  65. * @param DateTime $date_to_convert Date object instance. 
  66. * @return string 
  67. */ 
  68. private function to_timestamp( DateTime $date_to_convert ) { 
  69. return $date_to_convert->format( 'U' );