Skip to content

Commit 6c8290d

Browse files
committed
Adding phpstan support
1 parent e59dbb3 commit 6c8290d

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"require-dev": {
1616
"phpunit/phpunit": "^11",
1717
"friendsofphp/php-cs-fixer": "^3.14",
18-
"php-coveralls/php-coveralls": "^2.5"
18+
"php-coveralls/php-coveralls": "^2.5",
19+
"phpstan/phpstan": "^2.1"
1920
},
2021
"autoload": {
2122
"psr-4": {"ReCaptcha\\": "src/ReCaptcha"}
@@ -33,6 +34,7 @@
3334
"vendor/bin/php-cs-fixer -vvv fix --using-cache=no ."
3435
],
3536
"test": [
37+
"vendor/bin/phpstan",
3638
"vendor/bin/phpunit --display-phpunit-deprecations"
3739
],
3840
"serve-examples": "@php -S localhost:8080 -t examples"

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 5
3+
errorFormat: raw
4+
editorUrl: '%%file%% %%line%% %%column%%: %%error%%'
5+
paths:
6+
- src
7+

src/ReCaptcha/ReCaptcha.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,6 @@ class ReCaptcha
112112
*/
113113
public const E_CHALLENGE_TIMEOUT = 'challenge-timeout';
114114

115-
/**
116-
* Shared secret for the site.
117-
* @var string
118-
*/
119-
private string $secret;
120-
121-
/**
122-
* Method used to communicate with service. Defaults to POST request.
123-
* @var RequestMethod
124-
*/
125-
private ?RequestMethod $requestMethod;
126-
127115
private string $hostname;
128116
private string $apkPackageName;
129117
private string $action;
@@ -137,18 +125,15 @@ class ReCaptcha
137125
* @param ?RequestMethod $requestMethod method used to send the request. Defaults to POST.
138126
* @throws \RuntimeException if $secret is invalid
139127
*/
140-
public function __construct(string $secret, ?RequestMethod $requestMethod = null)
128+
public function __construct(private string $secret, private ?RequestMethod $requestMethod = null)
141129
{
142130
if (empty($secret)) {
143131
throw new \RuntimeException('No secret provided');
144132
}
145133

146-
if (!is_string($secret)) {
147-
throw new \RuntimeException('The provided secret must be a string');
134+
if (is_null($requestMethod)) {
135+
$this->requestMethod = new RequestMethod\Post();
148136
}
149-
150-
$this->secret = $secret;
151-
$this->requestMethod = (is_null($requestMethod)) ? new RequestMethod\Post() : $requestMethod;
152137
}
153138

154139
/**

src/ReCaptcha/RequestMethod/Curl.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Curl
4343
/**
4444
* @see http://php.net/curl_init
4545
*
46-
* @return resource cURL handle *
46+
* @return \CurlHandle|false cURL handle *
4747
*/
4848
public function init(?string $url = null)
4949
{
@@ -52,7 +52,7 @@ public function init(?string $url = null)
5252

5353
/**
5454
* @see http://php.net/curl_setopt_array
55-
* @param resource $ch
55+
* @param \CurlHandle|false $ch
5656
*/
5757
public function setoptArray($ch, array $options): bool
5858
{
@@ -61,7 +61,7 @@ public function setoptArray($ch, array $options): bool
6161

6262
/**
6363
* @see http://php.net/curl_exec
64-
* @param resource $ch
64+
* @param \CurlHandle|false $ch
6565
*/
6666
public function exec($ch): mixed
6767
{
@@ -70,7 +70,7 @@ public function exec($ch): mixed
7070

7171
/**
7272
* @see http://php.net/curl_close
73-
* @param resource $ch
73+
* @param \CurlHandle|false $ch
7474
*/
7575
public function close($ch): void
7676
{

src/ReCaptcha/RequestMethod/Socket.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
*/
4242
class Socket
4343
{
44+
/**
45+
* @var resource|false
46+
*/
4447
private $handle = null;
4548

4649
/**

0 commit comments

Comments
 (0)