Skip to content

Commit c775e26

Browse files
committed
Specify types for all function parameters
Removes PHP 8.4 depreciation warnings and just good style
1 parent 21944c7 commit c775e26

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

src/ReCaptcha/ReCaptcha.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ReCaptcha
136136
* @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
137137
* @throws \RuntimeException if $secret is invalid
138138
*/
139-
public function __construct($secret, RequestMethod $requestMethod = null)
139+
public function __construct($secret, ?RequestMethod $requestMethod = null)
140140
{
141141
if (empty($secret)) {
142142
throw new \RuntimeException('No secret provided');
@@ -158,7 +158,7 @@ public function __construct($secret, RequestMethod $requestMethod = null)
158158
* @param string $remoteIp The end user's IP address.
159159
* @return Response Response from the service.
160160
*/
161-
public function verify($response, $remoteIp = null)
161+
public function verify(string $response, ?string $remoteIp = null)
162162
{
163163
// Discard empty solution submissions
164164
if (empty($response)) {
@@ -217,7 +217,7 @@ public function verify($response, $remoteIp = null)
217217
* @param string $hostname Expected hostname
218218
* @return ReCaptcha Current instance for fluent interface
219219
*/
220-
public function setExpectedHostname($hostname)
220+
public function setExpectedHostname(string $hostname)
221221
{
222222
$this->hostname = $hostname;
223223
return $this;
@@ -229,7 +229,7 @@ public function setExpectedHostname($hostname)
229229
* @param string $apkPackageName Expected APK package name
230230
* @return ReCaptcha Current instance for fluent interface
231231
*/
232-
public function setExpectedApkPackageName($apkPackageName)
232+
public function setExpectedApkPackageName(string $apkPackageName)
233233
{
234234
$this->apkPackageName = $apkPackageName;
235235
return $this;
@@ -242,7 +242,7 @@ public function setExpectedApkPackageName($apkPackageName)
242242
* @param string $action Expected action
243243
* @return ReCaptcha Current instance for fluent interface
244244
*/
245-
public function setExpectedAction($action)
245+
public function setExpectedAction(string $action)
246246
{
247247
$this->action = $action;
248248
return $this;
@@ -255,7 +255,7 @@ public function setExpectedAction($action)
255255
* @param float $threshold Expected threshold
256256
* @return ReCaptcha Current instance for fluent interface
257257
*/
258-
public function setScoreThreshold($threshold)
258+
public function setScoreThreshold(float $threshold)
259259
{
260260
$this->threshold = floatval($threshold);
261261
return $this;
@@ -267,7 +267,7 @@ public function setScoreThreshold($threshold)
267267
* @param int $timeoutSeconds Expected hostname
268268
* @return ReCaptcha Current instance for fluent interface
269269
*/
270-
public function setChallengeTimeout($timeoutSeconds)
270+
public function setChallengeTimeout(int $timeoutSeconds)
271271
{
272272
$this->timeoutSeconds = $timeoutSeconds;
273273
return $this;

src/ReCaptcha/RequestMethod/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Curl
4444
* @param string $url
4545
* @return resource cURL handle
4646
*/
47-
public function init($url = null)
47+
public function init(?string $url = null)
4848
{
4949
return curl_init($url);
5050
}

src/ReCaptcha/RequestMethod/CurlPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CurlPost implements RequestMethod
6363
* @param Curl $curl Curl resource
6464
* @param string $siteVerifyUrl URL for reCAPTCHA siteverify API
6565
*/
66-
public function __construct(Curl $curl = null, $siteVerifyUrl = null)
66+
public function __construct(?Curl $curl = null, ?string $siteVerifyUrl = null)
6767
{
6868
$this->curl = (is_null($curl)) ? new Curl() : $curl;
6969
$this->siteVerifyUrl = (is_null($siteVerifyUrl)) ? ReCaptcha::SITE_VERIFY_URL : $siteVerifyUrl;

src/ReCaptcha/RequestMethod/Post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Post implements RequestMethod
5454
*
5555
* @param string $siteVerifyUrl URL for reCAPTCHA siteverify API
5656
*/
57-
public function __construct($siteVerifyUrl = null)
57+
public function __construct(?string $siteVerifyUrl = null)
5858
{
5959
$this->siteVerifyUrl = (is_null($siteVerifyUrl)) ? ReCaptcha::SITE_VERIFY_URL : $siteVerifyUrl;
6060
}

src/ReCaptcha/RequestMethod/Socket.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Socket
5353
* @param float $timeout
5454
* @return resource
5555
*/
56-
public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null)
56+
public function fsockopen(string $hostname, int $port = -1, int &$errno = 0, string &$errstr = '', ?float $timeout = null)
5757
{
5858
$this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout));
5959

@@ -71,7 +71,7 @@ public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $ti
7171
* @param int $length
7272
* @return int | bool
7373
*/
74-
public function fwrite($string, $length = null)
74+
public function fwrite(string $string, ?int $length = null)
7575
{
7676
return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length));
7777
}
@@ -83,7 +83,7 @@ public function fwrite($string, $length = null)
8383
* @param int $length
8484
* @return string
8585
*/
86-
public function fgets($length = null)
86+
public function fgets(?int $length = null)
8787
{
8888
return fgets($this->handle, $length);
8989
}

src/ReCaptcha/RequestMethod/SocketPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SocketPost implements RequestMethod
5959
* @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing
6060
* @param string $siteVerifyUrl URL for reCAPTCHA siteverify API
6161
*/
62-
public function __construct(Socket $socket = null, $siteVerifyUrl = null)
62+
public function __construct(?Socket $socket = null, ?string $siteVerifyUrl = null)
6363
{
6464
$this->socket = (is_null($socket)) ? new Socket() : $socket;
6565
$this->siteVerifyUrl = (is_null($siteVerifyUrl)) ? ReCaptcha::SITE_VERIFY_URL : $siteVerifyUrl;

src/ReCaptcha/RequestParameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class RequestParameters
7171
* @param string $remoteIp User's IP address.
7272
* @param string $version Version of this client library.
7373
*/
74-
public function __construct($secret, $response, $remoteIp = null, $version = null)
74+
public function __construct(string $secret, string $response, ?string $remoteIp = null, ?string $version = null)
7575
{
7676
$this->secret = $secret;
7777
$this->response = $response;

src/ReCaptcha/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Response
8787
* @param string $json
8888
* @return \ReCaptcha\Response
8989
*/
90-
public static function fromJson($json)
90+
public static function fromJson(string $json)
9191
{
9292
$responseData = json_decode($json, true);
9393

@@ -123,7 +123,7 @@ public static function fromJson($json)
123123
* @param string $action
124124
* @param array $errorCodes
125125
*/
126-
public function __construct($success, array $errorCodes = array(), $hostname = '', $challengeTs = '', $apkPackageName = '', $score = null, $action = '')
126+
public function __construct(bool $success, array $errorCodes = [], string $hostname = '', string $challengeTs = '', string $apkPackageName = '', ?float $score = null, string $action = '')
127127
{
128128
$this->success = $success;
129129
$this->hostname = $hostname;

0 commit comments

Comments
 (0)