Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 7 additions & 28 deletions src/ReCaptcha/RequestParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,8 @@
/**
* Stores and formats the parameters for the request to the reCAPTCHA service.
*/
class RequestParameters
readonly class RequestParameters
{
/**
* The shared key between your site and reCAPTCHA.
*/
private string $secret;

/**
* The user response token provided by reCAPTCHA, verifying the user on your site.
*/
private string $response;

/**
* Remote user's IP address.
*/
private ?string $remoteIp;

/**
* Client version.
*/
private ?string $version;

/**
* Initialise parameters.
*
Expand All @@ -72,13 +52,12 @@ class RequestParameters
* @param null|string $remoteIp user's IP address
* @param null|string $version version of this client library
*/
public function __construct(string $secret, string $response, ?string $remoteIp = null, ?string $version = null)
{
$this->secret = $secret;
$this->response = $response;
$this->remoteIp = $remoteIp;
$this->version = $version;
}
public function __construct(
private string $secret,
private string $response,
private ?string $remoteIp = null,
private ?string $version = null,
) {}

/**
* Array representation.
Expand Down
68 changes: 18 additions & 50 deletions src/ReCaptcha/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,60 +42,28 @@
/**
* The response returned from the service.
*/
class Response
readonly class Response
{
/**
* Success or failure.
*/
private bool $success = false;

/**
* Error code strings.
*
* @var array<string>
*/
private array $errorCodes = [];

/**
* The hostname of the site where the reCAPTCHA was solved.
*/
private string $hostname;

/**
* Timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ).
*/
private string $challengeTs;

/**
* APK package name.
*/
private string $apkPackageName;

/**
* Score assigned to the request.
*/
private ?float $score;

/**
* Action as specified by the page.
*/
private string $action;

/**
* Constructor.
*
* @param array<string> $errorCodes
*/
public function __construct(bool $success, array $errorCodes = [], string $hostname = '', string $challengeTs = '', string $apkPackageName = '', ?float $score = null, string $action = '')
{
$this->success = $success;
$this->hostname = $hostname;
$this->challengeTs = $challengeTs;
$this->apkPackageName = $apkPackageName;
$this->score = $score;
$this->action = $action;
$this->errorCodes = $errorCodes;
}
* @param bool $success success or failure
* @param array<string> $errorCodes error code strings
* @param string $hostname the hostname of the site where the reCAPTCHA was solved
* @param string $challengeTs timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
* @param string $apkPackageName APK package name
* @param ?float $score score assigned to the request
* @param string $action action as specified by the page
*/
public function __construct(
private bool $success,
private array $errorCodes = [],
private string $hostname = '',
private string $challengeTs = '',
private string $apkPackageName = '',
private ?float $score = null,
private string $action = '',
) {}

/**
* Build the response from the expected JSON returned by the service.
Expand Down
Loading