class-gsc-issue.php
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @package WPSEO\Admin|Google_Search_Console
*/
/**
* Class WPSEO_GSC_Issue
*/
class WPSEO_GSC_Issue {
/**
* @var string
*/
private $url;
/**
* @var DateTime
*/
private $first_detected;
/**
* @var DateTime
*/
private $last_crawled;
/**
* @var string
*/
private $response_code;
/**
* Constructor
*
* @param string $url
* @param DateTime $first_detected
* @param DateTime $last_crawled
* @param string $response_code
*/
public function __construct( $url, DateTime $first_detected, DateTime $last_crawled, $response_code ) {
$this->url = $url;
$this->first_detected = $first_detected;
$this->last_crawled = $last_crawled;
$this->response_code = $response_code;
}
/**
* Put the class properties in array
*
* @return array
*/
public function to_array() {
return array(
'url' => $this->url,
'first_detected' => $this->to_date_format( $this->first_detected ),
'first_detected_raw' => $this->to_timestamp( $this->first_detected ),
'last_crawled' => $this->to_date_format( $this->last_crawled ),
'last_crawled_raw' => $this->to_timestamp( $this->last_crawled ),
'response_code' => $this->response_code,
);
}
/**
* Converting the date to a date format
*
* @param DateTime $date_to_convert
* @param string $format
*
* @return string
*/
private function to_date_format( DateTime $date_to_convert, $format = 'Y-m-d H:i:s' ) {
return (string) strftime( '%x', strtotime( $date_to_convert->format( $format ) ) );
}
/**
* Converting the date to a timestamp
*
* @param DateTime $date_to_convert
*
* @return string
*/
private function to_timestamp( DateTime $date_to_convert ) {
return $date_to_convert->format( 'U' );
}
}