Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
* Added Laravel 6 compatibility.
Browse files Browse the repository at this point in the history
* Added some PHPDocs to some classes, mainly Exceptions.
* Minor fix to the Transparent Recaptcha (uses the already resolved reCaptcha service instead of resolving it again).
* Updated Travis CI build without PHP 7.1
  • Loading branch information
DarkGhostHunter committed Oct 20, 2019
1 parent 32fe3c3 commit 0ab2828
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
language: php

php:
- 7.1
- 7.2
- 7.3

env:
global:
- CC_TEST_REPORTER_ID=3cb0149c1ae23214062407321730aa13a558d9e10aa7011e01282b5a46e7f100

before_script:
install:
- travis_retry composer self-update
- travis_retry composer require php-coveralls/php-coveralls:2.1.* --dev
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- travis_retry curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter

before_script:
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

script:
- ./vendor/bin/phpunit

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

Expand Down
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
"php": "^7.1.3",
"ext-json" : "*",
"google/recaptcha": "^1.2",
"illuminate/config": "5.8.*",
"illuminate/container": "5.8.*",
"illuminate/http": "5.8.*",
"illuminate/routing": "5.8.*",
"illuminate/support": "5.8.*",
"illuminate/validation": "5.8.*",
"illuminate/view": "5.8.*"
"illuminate/config": "6.*",
"illuminate/container": "6.*",
"illuminate/http": "6.*",
"illuminate/routing": "6.*",
"illuminate/support": "6.*",
"illuminate/validation": "6.*",
"illuminate/view": "6.*"
},
"require-dev": {
"orchestra/testbench": "3.8.*",
"phpunit/phpunit": "^7.0"
"orchestra/testbench": "4.*"
},
"autoload": {
"files": [
Expand Down
3 changes: 1 addition & 2 deletions src/Exceptions/CaptchavelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

interface CaptchavelException
{

}
}
9 changes: 7 additions & 2 deletions src/Exceptions/FailedRecaptchaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

class FailedRecaptchaException extends Exception implements CaptchavelException
{
public function __construct(array $errorCodes)
/**
* Creates a new FailedRecaptchaException instance.
*
* @param array $errorCodes
*/
public function __construct(array $errorCodes = [])
{
$this->message = 'The Google reCAPTCHA library returned the following errors:' .
implode("\n- ", $errorCodes);
implode("\n- ", $errorCodes);

parent::__construct();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Exceptions/InvalidCaptchavelMiddlewareMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@

class InvalidCaptchavelMiddlewareMethod extends Exception implements CaptchavelException
{
/**
* The exception message
*
* @var string
*/
protected $message = 'Captchavel does not work in GET routes.';
}
12 changes: 12 additions & 0 deletions src/Exceptions/InvalidRecaptchaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@

class InvalidRecaptchaException extends Exception implements CaptchavelException
{
/**
* The exception message
*
* @var string
*/
protected $message = 'The reCAPTCHA token is empty';

/**
* Creates a new InvalidRecaptchaException instance.
*
* @param null $token
* @param int $code
* @param \Throwable|null $previous
*/
public function __construct($token = null, $code = 0, Throwable $previous = null)
{
if ($token !== null) {
Expand Down
5 changes: 5 additions & 0 deletions src/Exceptions/RecaptchaNotResolvedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@

class RecaptchaNotResolvedException extends Exception implements CaptchavelException
{
/**
* The exception message
*
* @var string
*/
protected $message = 'The reCAPTCHA has not been verified in this Request.';
}
9 changes: 5 additions & 4 deletions src/Http/Middleware/TransparentRecaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TransparentRecaptcha extends CheckRecaptcha
/**
* Return if the Request has a valid reCAPTCHA token
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return bool
* @throws \Throwable
*/
Expand All @@ -35,13 +35,14 @@ protected function hasValidRequest(Request $request)
*/
protected function resolve(Request $request, float $threshold)
{
return app('recaptcha')->setResponse(
new Response(true,
return $this->reCaptcha->setResponse(
new Response(
true,
[],
null,
now()->toIso8601ZuluString(),
null,
$request->query->has('is_robot') || $request->input('is_robot') === true ? 0 : 1,
(int)$request->query->has('is_robot'),
$this->sanitizeAction($request->getRequestUri()))
);
}
Expand Down

0 comments on commit 0ab2828

Please sign in to comment.