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
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
php: ['8.4', '8.5']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -32,7 +32,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" colors="true" bootstrap="src/autoload.php" cacheDirectory=".phpunit.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.0/phpunit.xsd" colors="true" bootstrap="src/autoload.php" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
Expand Down
2 changes: 2 additions & 0 deletions src/ReCaptcha/ReCaptcha.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions src/ReCaptcha/RequestMethod.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
16 changes: 11 additions & 5 deletions src/ReCaptcha/RequestMethod/CurlPost.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down Expand Up @@ -89,12 +91,16 @@ public function submit(RequestParameters $params): string
];
curl_setopt_array($handle, $options);

$response = curl_exec($handle);
try {
$response = curl_exec($handle);

if (is_string($response)) {
return $response;
}
if (is_string($response)) {
return $response;
}

return '{"success": false, "error-codes": ["'.ReCaptcha::E_CONNECTION_FAILED.'"]}';
return '{"success": false, "error-codes": ["'.ReCaptcha::E_CONNECTION_FAILED.'"]}';
} finally {
curl_close($handle);
}
}
}
2 changes: 2 additions & 0 deletions src/ReCaptcha/RequestMethod/Post.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions src/ReCaptcha/RequestMethod/SocketPost.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions src/ReCaptcha/RequestParameters.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions src/ReCaptcha/Response.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 1 addition & 1 deletion src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/

spl_autoload_register(function ($class) {
if ('ReCaptcha\\' !== substr($class, 0, 10)) {
if (!str_starts_with($class, 'ReCaptcha\\')) {
/* If the class does not lie under the "ReCaptcha" namespace,
* then we can exit immediately.
*/
Expand Down
4 changes: 3 additions & 1 deletion tests/ReCaptcha/ReCaptchaTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down Expand Up @@ -90,6 +92,7 @@ public static function invalidSecretProvider(): array
[null],
[new \stdClass()],
[[]],
[0],
];
}

Expand All @@ -109,7 +112,6 @@ public static function emptySecretProvider(): array
{
return [
[''],
[0],
];
}

Expand Down
10 changes: 10 additions & 0 deletions tests/ReCaptcha/RequestMethod/CurlPostTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down Expand Up @@ -86,6 +88,14 @@ function curl_exec(\stdClass $ch): bool|string
return CurlPostGlobalState::$execResponse;
}

/**
* Mock curl_close in the ReCaptcha\RequestMethod namespace.
*/
function curl_close(\stdClass $ch): void
{
// no-op mock
}

/**
* @internal
*
Expand Down
2 changes: 2 additions & 0 deletions tests/ReCaptcha/RequestMethod/PostTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/ReCaptcha/RequestMethod/SocketPostTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/ReCaptcha/RequestParametersTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/ReCaptcha/ResponseTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a PHP library that handles calling reCAPTCHA.
*
Expand Down
Loading