Skip to content

Commit

Permalink
Podpora pro PHP 7.4 a PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanPala committed Mar 5, 2021
1 parent 77ff939 commit df3460a
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 85 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0

script:
- vendor/bin/phpcs src/ tests/ --ignore="assets/*" --standard=vendor/pd/coding-standard/src/PeckaCodingStandard/ruleset.xml
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.4 || ^8.0",
"ext-json": "*",
"nette/application": "~2.4|~3.0.0|~3.1.0",
"nette/forms": "~2.4|~3.0.0",
"contributte/recaptcha": "3.1.* | 3.2.* | 3.3.*",
"contributte/recaptcha": "^3.1",
"nette/di": "~2.4|~3.0.0",
"nette/utils": "~2.4|~3.0.0|~3.1.0",
"pd/utils": "^1.0"
},
"require-dev": {
"nette/tester": "~2.3.2",
"mockery/mockery": "^1.0",
"pd/coding-standard": "1.21.*",
"pd/coding-standard": "1.27.*",
"phpstan/phpstan": "0.12.77"
},
"autoload": {
Expand Down
2 changes: 2 additions & 0 deletions src/DI/PdFormsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

final class PdFormsExtension extends \Nette\DI\CompilerExtension
{

public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
Expand All @@ -19,4 +20,5 @@ public function loadConfiguration(): void
$builder->addDefinition($this->prefix('versioningProvider'))
->setFactory(\Pd\Forms\Versioning\DummyProvider::class);
}

}
20 changes: 7 additions & 13 deletions src/InvisibleReCaptcha/InvisibleReCaptchaInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

class InvisibleReCaptchaInput extends \Contributte\ReCaptcha\Forms\ReCaptchaField
{
/**
* @var \Contributte\ReCaptcha\ReCaptchaProvider
*/
private $provider;

/**
* @var \Nette\Application\UI\Form
*/
private $form;
private \Contributte\ReCaptcha\ReCaptchaProvider $provider;

/**
* @var \Pd\Forms\Versioning\Provider
*/
private $versioningProvider;
private \Nette\Application\UI\Form $form;

private \Pd\Forms\Versioning\Provider $versioningProvider;


/**
Expand All @@ -26,7 +18,7 @@ class InvisibleReCaptchaInput extends \Contributte\ReCaptcha\Forms\ReCaptchaFiel
public function __construct(\Contributte\ReCaptcha\ReCaptchaProvider $provider, \Nette\Application\UI\Form $form, string $errorMessage, \Pd\Forms\Versioning\Provider $versioningProvider)
{
parent::__construct($provider);

$this->setMessage($errorMessage);
$this->setRequired();

Expand All @@ -35,6 +27,7 @@ public function __construct(\Contributte\ReCaptcha\ReCaptchaProvider $provider,
$this->versioningProvider = $versioningProvider;
}


/**
* @return \Nette\Utils\Html<\Nette\Utils\Html|string>
*/
Expand All @@ -54,6 +47,7 @@ public function getControl(): \Nette\Utils\Html
return $container;
}


/**
* @param string|object $caption
* @return \Nette\Utils\Html<\Nette\Utils\Html|string>|string
Expand Down
13 changes: 4 additions & 9 deletions src/InvisibleReCaptcha/InvisibleReCaptchaInputFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

class InvisibleReCaptchaInputFactory
{
/**
* @var \Contributte\ReCaptcha\ReCaptchaProvider
*/
private $reCaptchaProvider;

/**
* @var \Pd\Forms\Versioning\Provider
*/
private $versioningProvider;

private \Contributte\ReCaptcha\ReCaptchaProvider $reCaptchaProvider;

private \Pd\Forms\Versioning\Provider $versioningProvider;


public function __construct(
Expand Down
29 changes: 10 additions & 19 deletions src/RuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

final class RuleOptions implements \JsonSerializable
{

public const STATUS_INVALID = 'invalid';
public const STATUS_VALID = 'valid';
public const STATUS_TIMEOUT = 'timeout';
Expand All @@ -14,44 +15,33 @@ final class RuleOptions implements \JsonSerializable
public const MESSAGE_INFO = 'info';
public const MESSAGE_VALID = 'valid';


/**
* @var array<string|null>
*/
private $validationMessages = [
private array $validationMessages = [
self::STATUS_INVALID => NULL,
self::STATUS_VALID => NULL,
self::STATUS_TIMEOUT => '_form_validation_timeout',
];

/**
* @var \Nette\Localization\ITranslator
*/
private $translator;
private \Nette\Localization\ITranslator $translator;

/**
* @var bool
*/
private $optional;
private bool $optional;

/**
* @var string
*/
private $ajaxValidationTarget;
private ?string $ajaxValidationTarget = NULL;

/**
* @var \Pd\Forms\Validation\ValidationServiceInterface|null
*/
private $validationService;
private ?\Pd\Forms\Validation\ValidationServiceInterface $validationService = NULL;

/**
* @var \Nette\Forms\Controls\BaseControl[]
*/
private $dependentInputCollection = [];
private array $dependentInputCollection = [];

/**
* @var array<mixed>
*/
private $contextStorage = [];
private array $contextStorage = [];


public function __construct(
Expand Down Expand Up @@ -223,4 +213,5 @@ public function jsonSerialize()

return $serialized;
}

}
8 changes: 4 additions & 4 deletions src/RuleOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

final class RuleOptionsFactory
{

private const NETTE_RULE = 'netteRule';
private const NETTE_RULE_ARGS = 'netteRuleArgs';

/**
* @var \Nette\Localization\ITranslator
*/
private $translator;

private \Nette\Localization\ITranslator $translator;


public function __construct(
Expand Down Expand Up @@ -54,4 +53,5 @@ public function createNetteOptional(string $netteRule, $ruleArguments = NULL): \

return $options;
}

}
2 changes: 2 additions & 0 deletions src/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

final class Rules
{

public const AJAX = self::class . '::ajax';
public const NETTE_RULE_PROXY = self::class . '::netteRuleProxy';

Expand Down Expand Up @@ -97,4 +98,5 @@ public static function czechCompanyIdentifier(\Nette\Forms\IControl $control, ?\

return \Pd\Utils\Validators::isCzechCompanyIdentifier($control->getValue());
}

}
2 changes: 2 additions & 0 deletions src/Validation/AbstractValidationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

abstract class AbstractValidationController extends \Nette\Application\UI\Presenter implements \Pd\Forms\Validation\ValidationControllerInterface
{

public function actionDefault($inputValue = NULL, array $dependentInputs = []): void
{
if ( ! $inputValue) {
Expand All @@ -14,4 +15,5 @@ public function actionDefault($inputValue = NULL, array $dependentInputs = []):

$this->sendJson($validationResult);
}

}
2 changes: 2 additions & 0 deletions src/Validation/ValidationControllerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

interface ValidationControllerInterface
{

/**
* @param mixed $inputValue
* @param array<string> $dependentInputs
Expand All @@ -12,4 +13,5 @@ public function actionDefault($inputValue = NULL, array $dependentInputs = []):


public function getValidationService(): \Pd\Forms\Validation\ValidationServiceInterface;

}
18 changes: 5 additions & 13 deletions src/Validation/ValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@

final class ValidationResult implements \JsonSerializable
{
/**
* @var bool
*/
private $valid;

/**
* @var string|null
*/
private $status;
private bool $valid;

private ?string $status;

/**
* @var array<mixed>
*/
private $dependentInputs;
private array $dependentInputs;

/**
* @var string
*/
private $messageType;
private string $messageType = '';


public function __construct(bool $valid, ?string $status = NULL)
Expand Down
2 changes: 2 additions & 0 deletions src/Validation/ValidationServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

interface ValidationServiceInterface
{

/**
* @param mixed $value
* @param array<string> $dependentInputs
*/
public function validateInput($value, array $dependentInputs = []): \Pd\Forms\Validation\ValidationResult;

}
1 change: 1 addition & 0 deletions src/Versioning/DummyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public function generatePathWithVersion(string $filePath): string
{
return $filePath;
}

}
2 changes: 2 additions & 0 deletions src/Versioning/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

interface Provider
{

public function generatePathWithVersion(string $filePath): string;

}
14 changes: 8 additions & 6 deletions tests/Unit/Forms/RuleOptionsFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
*/
final class RuleOptionsFactoryTest extends \Tester\TestCase
{
/**
* @var \Pd\Forms\RuleOptionsFactory
*/
private $ruleOptionsFactory;

private \Pd\Forms\RuleOptionsFactory $ruleOptionsFactory;


public function testCreateOptions(): void
Expand All @@ -39,17 +37,21 @@ protected function setUp(): void

if (\interface_exists(\Nette\Schema\Schema::class)) { //nette 3.0
$translator = new class() implements \Nette\Localization\ITranslator {

function translate($message, ...$parameters): string
{
return '';
}
};

};
} else {
$translator = new class() implements \Nette\Localization\ITranslator {

public function translate($message, $count = NULL)
{
}
};

};
}

$this->ruleOptionsFactory = new \Pd\Forms\RuleOptionsFactory($translator);
Expand Down
Loading

0 comments on commit df3460a

Please sign in to comment.