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