Skip to content

Commit

Permalink
php 7.1, updated builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix Šulc committed Nov 25, 2018
1 parent ff987b8 commit 1617b07
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 290 deletions.
20 changes: 5 additions & 15 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

# Top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

# JS / PHP
[*.{js,php,phpt}]
charset = utf-8
indent_style = tab
indent_size = 4

# NEON
[*.neon]
charset = utf-8
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
indent_size = tab
tab_width = 4

# Composer, NPM, Travis, BitbucketPipelines
[{composer.json,package.json,.travis.yml,bitbucket-pipelines.yml}]
[{*.json,*.yml,*.md}]
indent_style = space
indent_size = 2
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
LICENSE export-ignore
README.md export-ignore
phpstan.neon export-ignore
ruleset.xml
README.md export-ignore
ruleset.xml export-ignore
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
/composer.lock

# Tests
/tests/*.log
/tests/tmp
/tests/coverage.html
/temp
/coverage.xml
48 changes: 23 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,62 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.1
- 7.2
- 7.3

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

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

script:
# Nette/Tester
- composer run-script tester
# Tests
- composer run-script tests

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

jobs:
include:
- env: title="Lowest Dependencies 5.6"
php: 5.6
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tester

- env: title="Lowest Dependencies 7.1"
php: 7.1
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tester
- composer run-script tests

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

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

- stage: Test Coverage
if: branch = master AND type = push
php: 7.1
script:
- composer run-script coverage
after_script:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- php coveralls.phar --verbose --config tests/.coveralls.yml
- 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

- stage: Phpstan
- stage: Outdated Dependencies
if: branch = master AND type = cron
php: 7.1
script:
- composer run-script phpstan-install
- composer run-script phpstan
- composer outdated --direct --strict

allow_failures:
- stage: Test Coverage
- stage: Phpstan

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

sudo: false

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Google reCAPTCHA implementation for [Nette Framework](https://github.com/nette/f
[![Build Status](https://img.shields.io/travis/contributte/reCAPTCHA.svg?style=flat-square)](https://travis-ci.org/contributte/reCAPTCHA)
[![Code coverage](https://img.shields.io/coveralls/contributte/reCAPTCHA.svg?style=flat-square)](https://coveralls.io/r/contributte/reCAPTCHA)
[![Licence](https://img.shields.io/packagist/l/contributte/reCAPTCHA.svg?style=flat-square)](https://packagist.org/packages/contributte/reCAPTCHA)

[![Downloads this Month](https://img.shields.io/packagist/dm/contributte/reCAPTCHA.svg?style=flat-square)](https://packagist.org/packages/contributte/reCAPTCHA)
[![Downloads total](https://img.shields.io/packagist/dt/contributte/reCAPTCHA.svg?style=flat-square)](https://packagist.org/packages/contributte/reCAPTCHA)
[![Latest stable](https://img.shields.io/packagist/v/contributte/reCAPTCHA.svg?style=flat-square)](https://packagist.org/packages/contributte/reCAPTCHA)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)

## Discussion / Help

Expand Down
22 changes: 12 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Google reCAPTCHA for Nette - Forms",
"keywords": ["nette", "forms", "captcha", "recaptcha", "google"],
"type": "library",
"license": ["MIT"],
"license": "MIT",
"homepage": "https://github.com/contributte/reCAPTCHA",
"authors": [
{
Expand All @@ -15,14 +15,14 @@
"ext-openssl": "To make requests via https"
},
"require": {
"php": ">= 5.6",
"php": ">= 7.1",
"nette/di": "~2.4.11",
"nette/forms": "~2.4.7",
"nette/utils": "~2.5.1"
"nette/utils": "~2.5.3"
},
"require-dev": {
"ninjify/qa": "^0.4.0",
"ninjify/nunjuck": "^0.2.0"
"ninjify/qa": "^0.8.0",
"ninjify/nunjuck": "^0.2.1"
},
"conflict": {
"nette/http": "<2.4.0"
Expand All @@ -37,19 +37,21 @@
"linter src tests",
"codesniffer src tests"
],
"tester": [
"tests": [
"tester -s -p php --colors 1 -C tests/cases"
],
"coverage": [
"tester -s -p php --colors 1 -C -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
"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.8.5",
"composer require -d temp/phpstan phpstan/phpstan-nette:0.8.3"
"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 1 -c phpstan.neon src"
"temp/phpstan/vendor/bin/phpstan analyse -l max -c phpstan.neon src"
]
},
"extra": {
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
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

parameters:
ignoreErrors:
# false positive
- '#^Cannot call method getHttpData\(\) on Nette\\Forms\\Form\|null\.$#'
# datasource is too much difficult to predict
- '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
15 changes: 8 additions & 7 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?xml version="1.0"?>
<ruleset name="Contributte">
<!-- Extending rulesets -->
<rule ref="vendor/ninjify/coding-standard/ruleset.xml"/>
<!-- My rules -->
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators.DisallowedEqualOperator"/>
</rule>

<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
Expand All @@ -11,10 +16,6 @@
</properties>
</rule>

<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition">
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.assignmentInCondition"/>
</rule>

<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<exclude-pattern>/tests</exclude-pattern>
</rule>
Expand Down
20 changes: 6 additions & 14 deletions src/DI/ReCaptchaExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\ReCaptcha\DI;

Expand All @@ -9,24 +9,19 @@
use Nette\PhpGenerator\ClassType;
use Nette\Utils\Validators;

/**
* @author Milan Felix Sulc <[email protected]>
*/
final class ReCaptchaExtension extends CompilerExtension
{

/** @var array */
/** @var mixed[] */
private $defaults = [
'siteKey' => NULL,
'secretKey' => NULL,
'siteKey' => null,
'secretKey' => null,
];

/**
* Register services
*
* @return void
*/
public function loadConfiguration()
public function loadConfiguration(): void
{
$config = $this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();
Expand All @@ -40,11 +35,8 @@ public function loadConfiguration()

/**
* Decorate initialize method
*
* @param ClassType $class
* @return void
*/
public function afterCompile(ClassType $class)
public function afterCompile(ClassType $class): void
{
$method = $class->getMethod('initialize');
$method->addBody(sprintf('%s::bind($this->getService(?));', ReCaptchaBinding::class), [$this->prefix('provider')]);
Expand Down
17 changes: 4 additions & 13 deletions src/Forms/InvisibleReCaptchaBinding.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\ReCaptcha\Forms;

use Contributte\ReCaptcha\ReCaptchaProvider;
use Nette\Forms\Container;

/**
* @author Milan Felix Sulc <[email protected]> | Jan Galek <[email protected]>
*/
final class InvisibleReCaptchaBinding
{

/**
* @param ReCaptchaProvider $provider
* @param string $name
* @return void
*/
public static function bind(ReCaptchaProvider $provider, $name = 'addInvisibleReCaptcha')
public static function bind(ReCaptchaProvider $provider, string $name = 'addInvisibleReCaptcha'): void
{
// Bind to form container

Container::extensionMethod($name, function ($container, $name = 'recaptcha', $required = TRUE) use ($provider) {
Container::extensionMethod($name, function (Container $container, string $name = 'recaptcha', bool $required = true) use ($provider): InvisibleReCaptchaField {
$field = new InvisibleReCaptchaField($provider);
$field->setRequired($required);
$container[$name] = $field;

return $container[$name];
return $field;
});
}

Expand Down
Loading

0 comments on commit 1617b07

Please sign in to comment.