Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/values/semrush
File: semrush-token.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Values\SEMrush;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Exceptions\SEMrush\Tokens\Empty_Property_Exception;
[4] Fix | Delete
use YoastSEO_Vendor\League\OAuth2\Client\Token\AccessTokenInterface;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Class SEMrush_Token
[8] Fix | Delete
*/
[9] Fix | Delete
class SEMrush_Token {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* The access token.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string
[15] Fix | Delete
*/
[16] Fix | Delete
public $access_token;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* The refresh token.
[20] Fix | Delete
*
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
public $refresh_token;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The expiration date.
[27] Fix | Delete
*
[28] Fix | Delete
* @var int
[29] Fix | Delete
*/
[30] Fix | Delete
public $expires;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Whether or not the token has expired.
[34] Fix | Delete
*
[35] Fix | Delete
* @var bool
[36] Fix | Delete
*/
[37] Fix | Delete
public $has_expired;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The timestamp at which the token was created.
[41] Fix | Delete
*
[42] Fix | Delete
* @var int
[43] Fix | Delete
*/
[44] Fix | Delete
public $created_at;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* SEMrush_Token constructor.
[48] Fix | Delete
*
[49] Fix | Delete
* @param string $access_token The access token.
[50] Fix | Delete
* @param string $refresh_token The refresh token.
[51] Fix | Delete
* @param int $expires The date and time at which the token will expire.
[52] Fix | Delete
* @param bool $has_expired Whether or not the token has expired.
[53] Fix | Delete
* @param int $created_at The timestamp of when the token was created.
[54] Fix | Delete
*
[55] Fix | Delete
* @throws Empty_Property_Exception Exception thrown if a token property is empty.
[56] Fix | Delete
*/
[57] Fix | Delete
public function __construct( $access_token, $refresh_token, $expires, $has_expired, $created_at ) {
[58] Fix | Delete
[59] Fix | Delete
if ( empty( $access_token ) ) {
[60] Fix | Delete
throw new Empty_Property_Exception( 'access_token' );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$this->access_token = $access_token;
[64] Fix | Delete
[65] Fix | Delete
if ( empty( $access_token ) ) {
[66] Fix | Delete
throw new Empty_Property_Exception( 'refresh_token' );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
$this->refresh_token = $refresh_token;
[70] Fix | Delete
[71] Fix | Delete
if ( empty( $expires ) ) {
[72] Fix | Delete
throw new Empty_Property_Exception( 'expires' );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
$this->expires = $expires;
[76] Fix | Delete
[77] Fix | Delete
if ( \is_null( $has_expired ) ) {
[78] Fix | Delete
throw new Empty_Property_Exception( 'has_expired' );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
$this->has_expired = $has_expired;
[82] Fix | Delete
$this->created_at = $created_at;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Creates a new instance based on the passed response.
[87] Fix | Delete
*
[88] Fix | Delete
* @param AccessTokenInterface $response The response object to create a new instance from.
[89] Fix | Delete
*
[90] Fix | Delete
* @return SEMrush_Token The token object.
[91] Fix | Delete
*
[92] Fix | Delete
* @throws Empty_Property_Exception Exception thrown if a token property is empty.
[93] Fix | Delete
*/
[94] Fix | Delete
public static function from_response( AccessTokenInterface $response ) {
[95] Fix | Delete
return new self(
[96] Fix | Delete
$response->getToken(),
[97] Fix | Delete
$response->getRefreshToken(),
[98] Fix | Delete
$response->getExpires(),
[99] Fix | Delete
$response->hasExpired(),
[100] Fix | Delete
\time()
[101] Fix | Delete
);
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Determines whether or not the token has expired.
[106] Fix | Delete
*
[107] Fix | Delete
* @return bool Whether or not the token has expired.
[108] Fix | Delete
*/
[109] Fix | Delete
public function has_expired() {
[110] Fix | Delete
return ( \time() >= $this->expires ) || $this->has_expired === true;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Converts the object to an array.
[115] Fix | Delete
*
[116] Fix | Delete
* @return array The converted object.
[117] Fix | Delete
*/
[118] Fix | Delete
public function to_array() {
[119] Fix | Delete
return [
[120] Fix | Delete
'access_token' => $this->access_token,
[121] Fix | Delete
'refresh_token' => $this->refresh_token,
[122] Fix | Delete
'expires' => $this->expires,
[123] Fix | Delete
'has_expired' => $this->has_expired(),
[124] Fix | Delete
'created_at' => $this->created_at,
[125] Fix | Delete
];
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function