Skip to content

Commit

Permalink
Synchronize with latest contributte's bare repo
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jun 5, 2019
1 parent 8d077a6 commit df73b6d
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
Makefile export-ignore
phpstan.neon export-ignore
README.md export-ignore
ruleset.xml export-ignore
47 changes: 20 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- nightly

before_install:
# Turn off XDebug
- phpenv config-rm xdebug.ini || return 0
- phpenv config-rm xdebug.ini || return 0 # Turn off XDebug

install:
# Composer
- travis_retry composer install --no-progress --prefer-dist
- travis_retry composer install --no-progress --prefer-dist # Install dependencies

script:
# Tests
- composer run-script tests
- make tests # Tests

after_failure:
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done # Print *.actual content

jobs:
include:
- env: title="Lowest Dependencies 7.1"
php: 7.1
- env: title="Lowest Dependencies 7.2"
php: 7.2
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
script:
- composer run-script tests
- make tests

- stage: Quality Assurance
php: 7.1
php: 7.3
script:
- composer run-script qa

- stage: Phpstan
php: 7.1
script:
- composer run-script phpstan-install
- composer run-script phpstan
- make qa

- stage: Test Coverage
if: branch = master AND type = push
php: 7.1
php: 7.3
script:
- composer run-script coverage
- make coverage
after_script:
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
- php php-coveralls.phar --verbose --config tests/.coveralls.yml
- composer global require php-coveralls/php-coveralls ^2.1.0
- ~/.composer/vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml

- stage: Outdated Dependencies
if: branch = master AND type = cron
php: 7.1
php: 7.3
script:
- composer outdated --direct --strict
- composer outdated --direct

allow_failures:
- stage: Test Coverage
- php: 7.4snapshot
- php: nightly

sudo: false

Expand Down
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.PHONY: qa lint cs csf phpstan tests coverage

all:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

vendor: composer.json composer.lock
composer install

qa: lint phpstan cs

lint: vendor
vendor/bin/linter src tests

cs: vendor
vendor/bin/codesniffer src tests

csf: vendor
vendor/bin/codefixer src tests

phpstan: vendor
vendor/bin/phpstan analyse -l max -c phpstan.neon src

tests: vendor
vendor/bin/tester -s -p php --colors 1 -C tests/cases

coverage: vendor
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ Google reCAPTCHA implementation for [Nette Framework](https://github.com/nette/f

| Branch | Composer | Nette | PHP | Readme |
|--------|------------|------ | ----- | -------|
| latest | ~3.1.0 | 2.4 | >=5.6 | - |
| 2.x | ~2.1.0 | 2.4 | >=5.6 | [README-2.x](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-2.x.md) |
| 1.6.x | ~1.6.3 | 2.4 | >=5.6 | [README-1.6](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.6.md) |
| 1.5.x | ~1.5.2 | 2.3 | >=5.4 | [README-1.5](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.5.md) |
| 1.4.x | ~1.4.4 | 2.2 | >=5.4 | [README-1.4](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.4.md) |
| 1.3.x | ~1.3.0 | 2.1 | >=5.4 | [README-1.3](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.3.md) |
| dev | ~3.3.0 | 3.0+ | ^7.2 | - |
| latest | ~3.2.0 | 3.0+ | ^7.2 | - |
| 3.x | ~3.1.0 | 2.4 | ^7.1 | - |
| 2.x | ~2.1.0 | 2.4 | ^5.6 | [README-2.x](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-2.x.md) |
| 1.6.x | ~1.6.3 | 2.4 | ^5.6 | [README-1.6](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.6.md) |
| 1.5.x | ~1.5.2 | 2.3 | ^5.4 | [README-1.5](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.5.md) |
| 1.4.x | ~1.4.4 | 2.2 | ^5.4 | [README-1.4](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.4.md) |
| 1.3.x | ~1.3.0 | 2.1 | ^5.4 | [README-1.3](https://github.com/contributte/reCAPTCHA/blob/master/.docs/README-1.3.md) |

## Pre-installation

Expand Down
41 changes: 14 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,28 @@
"ext-openssl": "To make requests via https"
},
"require": {
"php": "^7.1",
"nette/di": "^3.0",
"nette/forms": "^3.0",
"nette/utils": "^3.0"
"php": "^7.2",
"nette/di": "~3.0.0",
"nette/forms": "~3.0.0",
"nette/utils": "~3.0.0"
},
"require-dev": {
"ninjify/qa": "^0.8.0",
"ninjify/nunjuck": "^0.2.1"
"ninjify/nunjuck": "^0.3.0",
"ninjify/qa": "^0.9.0",
"phpstan/phpstan-deprecation-rules": "^0.11",
"phpstan/phpstan-nette": "^0.11",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11"
},
"autoload": {
"psr-4": {
"Contributte\\ReCaptcha\\": "src"
}
},
"scripts": {
"qa": [
"linter src tests",
"codesniffer src tests"
],
"tests": [
"tester -s -p php --colors 1 -C tests/cases"
],
"coverage": [
"tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases"
],
"phpstan-install": [
"mkdir -p temp/phpstan",
"composer require -d temp/phpstan phpstan/phpstan:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-nette:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:^0.10"
],
"phpstan": [
"temp/phpstan/vendor/bin/phpstan analyse -l max -c phpstan.neon src"
]
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
Expand Down
8 changes: 4 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
includes:
- temp/phpstan/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
ignoreErrors:
Expand Down
19 changes: 10 additions & 9 deletions src/DI/ReCaptchaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
use Contributte\ReCaptcha\Forms\InvisibleReCaptchaBinding;
use Contributte\ReCaptcha\Forms\ReCaptchaBinding;
use Contributte\ReCaptcha\ReCaptchaProvider;
use Nette;
use Nette\DI\CompilerExtension;
use Nette\PhpGenerator\ClassType;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

final class ReCaptchaExtension extends CompilerExtension
{

public function getConfigSchema(): Schema
{
return Expect::structure([
'siteKey' => Expect::string()->required(),
'secretKey' => Expect::string()->required(),
]);
}

/**
* Register services
*/
Expand All @@ -34,12 +43,4 @@ public function afterCompile(ClassType $class): void
$method->addBody(sprintf('%s::bind($this->getService(?));', InvisibleReCaptchaBinding::class), [$this->prefix('provider')]);
}

public function getConfigSchema(): Nette\Schema\Schema
{
return Nette\Schema\Expect::structure([
'siteKey' => Nette\Schema\Expect::string()->required(),
'secretKey' => Nette\Schema\Expect::string()->required(),
]);
}

}
1 change: 1 addition & 0 deletions src/Forms/InvisibleReCaptchaBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static function bind(ReCaptchaProvider $provider, string $name = 'addInvi
$field = new InvisibleReCaptchaField($provider);
$field->setRequired($required);
$container[$name] = $field;

return $field;
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/Forms/InvisibleReCaptchaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function loadHttpData(): void
public function setMessage(string $message): self
{
$this->message = $message;

return $this;
}

Expand All @@ -53,6 +54,7 @@ public function validate(): void
public function getRules(): Rules
{
$this->configureValidation();

return parent::getRules();
}

Expand Down Expand Up @@ -83,6 +85,7 @@ public function getControl(?string $caption = null): Html
'data-sitekey' => $this->provider->getSiteKey(),
'data-size' => 'invisible',
]);

return $el;
}

Expand Down
1 change: 1 addition & 0 deletions src/Forms/ReCaptchaBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function bind(ReCaptchaProvider $provider, string $name = 'addReCa
$field = new ReCaptchaField($provider, $label, $message);
$field->setRequired($required);
$container[$name] = $field;

return $field;
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/Forms/ReCaptchaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function loadHttpData(): void
public function setMessage(string $message): self
{
$this->message = $message;

return $this;
}

Expand All @@ -52,6 +53,7 @@ public function validate(): void
public function getRules(): Rules
{
$this->configureValidation();

return parent::getRules();
}

Expand Down Expand Up @@ -83,6 +85,7 @@ public function getControl(): Html
'name' => $this->getHtmlName(),
'data-sitekey' => $this->provider->getSiteKey(),
]);

return $el;
}

Expand Down
14 changes: 7 additions & 7 deletions src/ReCaptchaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,15 @@ public function validate($response): ?ReCaptchaResponse
$response = $this->makeRequest($response);

// Response is empty or failed..
if (empty($response)) return null;
if (empty($response)) {
return null;
}

// Decode server answer (with key assoc reserved)
$answer = json_decode($response, true);

// Return response
if ($answer['success'] === true) {
return new ReCaptchaResponse(true);
} else {
return new ReCaptchaResponse(false, $answer['error-codes'] ?? null);
}
return $answer['success'] === true ? new ReCaptchaResponse(true) : new ReCaptchaResponse(false, $answer['error-codes'] ?? null);
}

public function validateControl(BaseControl $control): bool
Expand All @@ -88,7 +86,9 @@ public function validateControl(BaseControl $control): bool
*/
protected function makeRequest($response, ?string $remoteIp = null)
{
if (empty($response)) return null;
if (empty($response)) {
return null;
}

$params = [
'secret' => $this->secretKey,
Expand Down

0 comments on commit df73b6d

Please sign in to comment.