From 924c9cd22596a3326f8a9fa09b01fd5e247a0651 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 21 Oct 2026 05:54:53 +0200 Subject: [PATCH 01/18] composer.json: updated description, keywords and homepage --- composer.json | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index fbe5d3edc..bcf5c4810 100644 --- a/composer.json +++ b/composer.json @@ -1,17 +1,13 @@ { "name": "nette/forms", - "description": "📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.", - "keywords": ["nette", "forms", "validation", "csrf", "javascript", "bootstrap"], - "homepage": "https://nette.org", + "description": "📝 Nette Forms: secure forms with one set of validation rules for server and browser, CSRF protection, and rendering done automatically or by hand in Latte.", + "keywords": ["nette", "forms", "form validation", "form builder", "client-side validation", "csrf"], + "homepage": "https://doc.nette.org/forms", "license": ["BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"], "authors": [ { "name": "David Grudl", "homepage": "https://davidgrudl.com" - }, - { - "name": "Nette Community", - "homepage": "https://nette.org/contributors" } ], "require": { From 700449e4b57d2f6424a400bed3690a17a88c77dc Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 5 Aug 2026 03:13:10 +0200 Subject: [PATCH 02/18] updated github actions --- .github/workflows/static-analysis.yml | 4 ++-- .github/workflows/tests.yml | 24 ++++++++++++------------ tests/.coveralls.yml | 4 ---- 3 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 tests/.coveralls.yml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index b5b0dffcd..d2471c593 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -7,10 +7,10 @@ jobs: name: PHPStan runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: - php-version: 8.2 + php-version: 8.6 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d37351408..465e22d7b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: name: PHP ${{ matrix.php }} tests steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} @@ -22,7 +22,7 @@ jobs: - run: composer install --no-progress --prefer-dist - run: composer tester - if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: output-${{ matrix.php }} path: tests/**/output @@ -32,7 +32,7 @@ jobs: name: Lowest Dependencies runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: php-version: 8.1 @@ -45,26 +45,26 @@ jobs: code_coverage: name: Code Coverage runs-on: ubuntu-latest - continue-on-error: true steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: php-version: 8.1 - coverage: none + coverage: pcov - run: composer install --no-progress --prefer-dist - - run: composer tester -- -p phpdbg --coverage ./coverage.xml --coverage-src ./src - - run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar - - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: php php-coveralls.phar --verbose --config tests/.coveralls.yml + - run: composer tester -- --coverage ./coverage.xml --coverage-src ./src + continue-on-error: true + - uses: coverallsapp/github-action@v2 + with: + file: coverage.xml + format: clover jasmine: name: JavaScript tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - run: npm install - run: npm run test diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml deleted file mode 100644 index 845038250..000000000 --- a/tests/.coveralls.yml +++ /dev/null @@ -1,4 +0,0 @@ -# for php-coveralls -service_name: github-actions -coverage_clover: coverage.xml -json_path: coverage.json From 436e84798de80417a55a419c24cd5451f52c6d5a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 04:57:48 +0100 Subject: [PATCH 03/18] cs: only compiler-optimized functions in use-function imports --- src/Bridges/FormsDI/FormsExtension.php | 1 - src/Bridges/FormsLatte/FormsExtension.php | 1 - src/Bridges/FormsLatte/Runtime.php | 3 +-- src/Forms/Container.php | 8 ++++---- src/Forms/Controls/BaseControl.php | 2 +- src/Forms/Controls/CheckboxList.php | 4 ++-- src/Forms/Controls/ChoiceControl.php | 2 +- src/Forms/Controls/ColorPicker.php | 2 +- src/Forms/Controls/CsrfProtection.php | 1 - src/Forms/Controls/DateTimeControl.php | 2 +- src/Forms/Controls/HiddenField.php | 2 +- src/Forms/Controls/MultiChoiceControl.php | 2 +- src/Forms/Controls/RadioList.php | 4 ++-- src/Forms/Controls/TextBase.php | 2 +- src/Forms/Controls/TextInput.php | 10 +++++----- src/Forms/Controls/UploadControl.php | 2 +- src/Forms/Form.php | 7 +++---- src/Forms/Helpers.php | 5 +++-- src/Forms/Rendering/DefaultFormRenderer.php | 3 +-- src/Forms/Rules.php | 2 +- src/Forms/Validator.php | 2 +- 21 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/Bridges/FormsDI/FormsExtension.php b/src/Bridges/FormsDI/FormsExtension.php index 95207d0c5..cff15e247 100644 --- a/src/Bridges/FormsDI/FormsExtension.php +++ b/src/Bridges/FormsDI/FormsExtension.php @@ -8,7 +8,6 @@ namespace Nette\Bridges\FormsDI; use Nette; -use function defined; /** diff --git a/src/Bridges/FormsLatte/FormsExtension.php b/src/Bridges/FormsLatte/FormsExtension.php index d3fd98d17..50a5f5dc4 100644 --- a/src/Bridges/FormsLatte/FormsExtension.php +++ b/src/Bridges/FormsLatte/FormsExtension.php @@ -8,7 +8,6 @@ namespace Nette\Bridges\FormsLatte; use Latte; -use function strtolower; /** diff --git a/src/Bridges/FormsLatte/Runtime.php b/src/Bridges/FormsLatte/Runtime.php index e34dc45b6..f7225365b 100644 --- a/src/Bridges/FormsLatte/Runtime.php +++ b/src/Bridges/FormsLatte/Runtime.php @@ -10,8 +10,7 @@ use Nette; use Nette\Forms\Form; use Nette\Utils\Html; -use function end, explode, is_object, parse_url, preg_replace, preg_split, urldecode; -use const PHP_URL_QUERY; +use function is_object; /** diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 35d420224..b9030d903 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -10,7 +10,7 @@ use Nette; use Nette\Utils\ArrayHash; use Stringable; -use function array_combine, array_key_exists, array_map, array_merge, array_unique, explode, func_get_args, in_array, is_object, iterator_to_array, str_contains; +use function array_key_exists, func_get_args, is_object; /** @@ -102,10 +102,10 @@ public function getValues(string|object|bool|null $returnType = null, ?array $co if ($controls === null && $submitter instanceof SubmitterControl) { $controls = $submitter->getValidationScope(); - if ($controls !== null && !in_array($this, $controls, strict: true)) { + if ($controls !== null && !in_array($this, $controls, true)) { $scope = $this; while (($scope = $scope->getParent()) instanceof self) { - if (in_array($scope, $controls, strict: true)) { + if (in_array($scope, $controls, true)) { $controls[] = $this; break; } @@ -154,7 +154,7 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array $properties = array_combine(array_map(fn($p) => $p->getName(), $properties), $properties); foreach ($this->getComponents() as $name => $control) { - $allowed = $controls === null || in_array($this, $controls, strict: true) || in_array($control, $controls, strict: true); + $allowed = $controls === null || in_array($this, $controls, true) || in_array($control, $controls, true); $name = (string) $name; $property = $properties[$name] ?? null; if ( diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index c438949b6..f97d5948c 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -13,7 +13,7 @@ use Nette\Forms\Rules; use Nette\Utils\Html; use Stringable; -use function array_unique, explode, func_get_arg, func_num_args, get_parent_class, implode, is_array, sprintf, str_contains; +use function func_num_args, is_array; /** diff --git a/src/Forms/Controls/CheckboxList.php b/src/Forms/Controls/CheckboxList.php index 957899988..eb807267b 100644 --- a/src/Forms/Controls/CheckboxList.php +++ b/src/Forms/Controls/CheckboxList.php @@ -10,7 +10,7 @@ use Nette; use Nette\Utils\Html; use Stringable; -use function array_flip, array_key_first, array_keys, array_merge, explode, func_num_args, in_array, is_array, key, substr; +use function func_num_args, is_array, is_string; /** @@ -89,7 +89,7 @@ public function getControlPart($key = null): Html $key = key([(string) $key => null]); return parent::getControl()->addAttributes([ 'id' => $this->getHtmlId() . '-' . $key, - 'checked' => in_array($key, (array) $this->value, strict: true), + 'checked' => in_array($key, (array) $this->value, true), 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled, 'required' => null, 'value' => $key, diff --git a/src/Forms/Controls/ChoiceControl.php b/src/Forms/Controls/ChoiceControl.php index 835aba65c..b45baacbd 100644 --- a/src/Forms/Controls/ChoiceControl.php +++ b/src/Forms/Controls/ChoiceControl.php @@ -8,7 +8,7 @@ namespace Nette\Forms\Controls; use Nette; -use function array_combine, array_fill_keys, array_key_exists, array_keys, array_map, implode, is_array, key, var_export; +use function array_key_exists, is_array; /** diff --git a/src/Forms/Controls/ColorPicker.php b/src/Forms/Controls/ColorPicker.php index aac1c7b5a..50b13ef99 100644 --- a/src/Forms/Controls/ColorPicker.php +++ b/src/Forms/Controls/ColorPicker.php @@ -8,7 +8,7 @@ namespace Nette\Forms\Controls; use Nette; -use function is_string, ltrim, preg_match, strtolower; +use function is_string; /** diff --git a/src/Forms/Controls/CsrfProtection.php b/src/Forms/Controls/CsrfProtection.php index dab502500..7a89456ef 100644 --- a/src/Forms/Controls/CsrfProtection.php +++ b/src/Forms/Controls/CsrfProtection.php @@ -10,7 +10,6 @@ use Nette; use Nette\Application\UI\Presenter; use Stringable; -use function base64_encode, sha1, substr; /** diff --git a/src/Forms/Controls/DateTimeControl.php b/src/Forms/Controls/DateTimeControl.php index 359d1d440..1547e8dc8 100644 --- a/src/Forms/Controls/DateTimeControl.php +++ b/src/Forms/Controls/DateTimeControl.php @@ -10,7 +10,7 @@ use Nette; use Nette\Forms\Form; use Stringable; -use function get_debug_type, is_numeric, is_scalar, is_string; +use function is_scalar, is_string; /** diff --git a/src/Forms/Controls/HiddenField.php b/src/Forms/Controls/HiddenField.php index 5ac9d4f14..87c589687 100644 --- a/src/Forms/Controls/HiddenField.php +++ b/src/Forms/Controls/HiddenField.php @@ -10,7 +10,7 @@ use Nette; use Nette\Utils\Html; use Stringable; -use function get_debug_type, is_scalar, sprintf; +use function is_scalar, sprintf; /** diff --git a/src/Forms/Controls/MultiChoiceControl.php b/src/Forms/Controls/MultiChoiceControl.php index adf05599f..9d1a69dff 100644 --- a/src/Forms/Controls/MultiChoiceControl.php +++ b/src/Forms/Controls/MultiChoiceControl.php @@ -8,7 +8,7 @@ namespace Nette\Forms\Controls; use Nette; -use function array_combine, array_diff, array_fill_keys, array_flip, array_keys, array_map, count, get_debug_type, implode, is_array, is_scalar, sprintf, var_export; +use function count, is_array, is_scalar, sprintf; /** diff --git a/src/Forms/Controls/RadioList.php b/src/Forms/Controls/RadioList.php index d87c97613..1369ae073 100644 --- a/src/Forms/Controls/RadioList.php +++ b/src/Forms/Controls/RadioList.php @@ -10,7 +10,7 @@ use Nette; use Nette\Utils\Html; use Stringable; -use function array_merge, func_num_args, in_array, is_array, key; +use function func_num_args, is_array; /** @@ -84,7 +84,7 @@ public function getControlPart($key = null): Html $key = key([(string) $key => null]); return parent::getControl()->addAttributes([ 'id' => $this->getHtmlId() . '-' . $key, - 'checked' => in_array($key, (array) $this->value, strict: true), + 'checked' => in_array($key, (array) $this->value, true), 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled, 'value' => $key, ]); diff --git a/src/Forms/Controls/TextBase.php b/src/Forms/Controls/TextBase.php index 29d76cdf8..66b226fe8 100644 --- a/src/Forms/Controls/TextBase.php +++ b/src/Forms/Controls/TextBase.php @@ -11,7 +11,7 @@ use Nette\Forms\Form; use Nette\Utils\Strings; use Stringable; -use function get_debug_type, is_array, is_scalar, min, sprintf; +use function is_array, is_scalar, sprintf; /** diff --git a/src/Forms/Controls/TextInput.php b/src/Forms/Controls/TextInput.php index 49497a964..3dfd0a171 100644 --- a/src/Forms/Controls/TextInput.php +++ b/src/Forms/Controls/TextInput.php @@ -10,7 +10,7 @@ use Nette; use Nette\Forms\Form; use Stringable; -use function in_array, is_scalar, max, min; +use function in_array, is_scalar; /** @@ -75,13 +75,13 @@ public function addRule( } } - if ($this->control->type === null && in_array($validator, [Form::Email, Form::URL, Form::Integer], strict: true)) { + if ($this->control->type === null && in_array($validator, [Form::Email, Form::URL, Form::Integer], true)) { $types = [Form::Email => 'email', Form::URL => 'url', Form::Integer => 'number']; $this->control->type = $types[$validator]; } elseif ( - in_array($validator, [Form::Min, Form::Max, Form::Range], strict: true) - && in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], strict: true) + in_array($validator, [Form::Min, Form::Max, Form::Range], true) + && in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], true) ) { if ($validator === Form::Min) { $range = [$arg, null]; @@ -106,7 +106,7 @@ public function addRule( } elseif ( $validator === Form::Pattern && is_scalar($arg) - && in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], strict: true) + && in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], true) ) { $this->control->pattern = (string) $arg; } diff --git a/src/Forms/Controls/UploadControl.php b/src/Forms/Controls/UploadControl.php index aba37bcb5..997639b01 100644 --- a/src/Forms/Controls/UploadControl.php +++ b/src/Forms/Controls/UploadControl.php @@ -13,7 +13,7 @@ use Nette\Http\FileUpload; use Nette\Utils\Arrays; use Stringable; -use function implode, ini_get, is_array; +use function ini_get, is_array; /** diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 630881387..e245f6143 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -11,8 +11,7 @@ use Nette\Utils\Arrays; use Nette\Utils\Html; use Stringable; -use function array_key_first, array_merge, array_search, array_unique, count, headers_sent, in_array, is_array, is_scalar, is_string, sprintf, strcasecmp, strtolower; -use const PHP_SAPI; +use function count, in_array, is_array, is_scalar, is_string; /** @@ -342,7 +341,7 @@ public function removeGroup(string|ControlGroup $name): void if (is_string($name) && isset($this->groups[$name])) { $group = $this->groups[$name]; - } elseif ($name instanceof ControlGroup && in_array($name, $this->groups, strict: true)) { + } elseif ($name instanceof ControlGroup && in_array($name, $this->groups, true)) { $group = $name; $name = array_search($group, $this->groups, strict: true); @@ -753,7 +752,7 @@ public static function initialize(bool $reinit = false): void self::$defaultHttpRequest = (new Nette\Http\RequestFactory)->fromGlobals(); - if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], strict: true)) { + if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { if (headers_sent($file, $line)) { throw new Nette\InvalidStateException( 'Create a form or call Nette\Forms\Form::initialize() before the headers are sent to initialize CSRF protection.' diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index fe1a99053..2ee331c07 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -11,7 +11,8 @@ use Nette\Utils\Html; use Nette\Utils\Image; use Nette\Utils\Strings; -use function array_fill_keys, array_map, array_values, explode, html_entity_decode, htmlspecialchars, in_array, ini_get, is_a, is_array, is_numeric, is_scalar, is_string, str_ends_with, str_replace, strip_tags, strpos, strtolower, strtr, substr, substr_replace; +use function is_array, is_scalar, is_string; +use const ENT_HTML5, ENT_QUOTES; /** @@ -100,7 +101,7 @@ public static function generateHtmlName(string $id): string $name = substr_replace($name, '', $pos, 1) . ']'; } - if (is_numeric($name) || in_array($name, self::UnsafeNames, strict: true)) { + if (is_numeric($name) || in_array($name, self::UnsafeNames, true)) { $name = '_' . $name; } diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index 305b410c1..d9237aaf5 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -10,8 +10,7 @@ use Nette; use Nette\HtmlStringable; use Nette\Utils\Html; -use function array_merge, count, explode, implode, parse_url, preg_split, str_replace, strtolower, urldecode; -use const PHP_URL_QUERY; +use function count; /** diff --git a/src/Forms/Rules.php b/src/Forms/Rules.php index 411eac0bc..016fd84cd 100644 --- a/src/Forms/Rules.php +++ b/src/Forms/Rules.php @@ -9,7 +9,7 @@ use Nette; use Stringable; -use function array_merge, end, is_array, is_bool, is_callable, is_scalar, is_string, ltrim, ord, strncmp, strtoupper; +use function is_array, is_bool, is_scalar, is_string; /** diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index 82039636c..31f55a825 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -10,7 +10,7 @@ use Nette; use Nette\Utils\Strings; use Nette\Utils\Validators; -use function array_map, count, explode, in_array, is_array, is_float, is_int, is_object, is_string, preg_replace, preg_replace_callback, rtrim, str_replace, strtolower; +use function count, is_array, is_float, is_int, is_object, is_string; /** From 4757f71649c74b020e3c303fe80204e9c146353e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 04:57:53 +0100 Subject: [PATCH 04/18] cs: grouped use statements --- src/Bridges/FormsLatte/FormMacros.php | 4 +--- src/Bridges/FormsLatte/Nodes/FieldNNameNode.php | 13 +++---------- src/Bridges/FormsLatte/Nodes/FormContainerNode.php | 6 ++---- src/Bridges/FormsLatte/Nodes/FormNNameNode.php | 7 ++----- src/Bridges/FormsLatte/Nodes/FormNode.php | 7 ++----- src/Bridges/FormsLatte/Nodes/FormPrintNode.php | 3 +-- src/Bridges/FormsLatte/Nodes/InputErrorNode.php | 3 +-- src/Bridges/FormsLatte/Nodes/InputNode.php | 3 +-- src/Bridges/FormsLatte/Nodes/LabelNode.php | 7 ++----- src/Forms/Controls/BaseControl.php | 4 +--- src/Forms/Controls/SubmitButton.php | 3 +-- src/Forms/Form.php | 3 +-- src/Forms/Helpers.php | 4 +--- src/Forms/Rendering/DataClassGenerator.php | 3 +-- src/Forms/Rendering/LatteRenderer.php | 3 +-- src/Forms/Validator.php | 3 +-- tests/Controls/BaseControl.extensionMethod.phpt | 5 +---- tests/Controls/BaseControl.phpt | 3 +-- tests/Controls/CheckboxList.loadData.phpt | 3 +-- tests/Controls/DateTimeControl.value.phpt | 3 +-- tests/Controls/MultiChoiceControl.loadData.phpt | 3 +-- tests/Controls/MultiSelectBox.loadData.phpt | 3 +-- tests/Controls/SelectBox.isOk.phpt | 3 +-- tests/Controls/TestBase.validators.phpt | 3 +-- tests/Controls/UploadControl.loadData.phpt | 3 +-- tests/Forms.DI/FormsExtension.phpt | 3 +-- tests/Forms/Blueprint.dataClass.phpt | 3 +-- tests/Forms/Blueprint.latte.phpt | 3 +-- tests/Forms/Container.validate().phpt | 3 +-- tests/Forms/Container.values.mapping.phpt | 3 +-- tests/Forms/Forms.enum.phpt | 3 +-- tests/Forms/Forms.getHttpData.post.phpt | 3 +-- tests/Forms/Forms.validationScope.phpt | 3 +-- tests/Forms/Helpers.exportRules.phpt | 3 +-- tests/Forms/Helpers.extractHttpData.phpt | 3 +-- tests/Forms/Rules.static.phpt | 3 +-- tests/types/forms-types.php | 3 +-- 37 files changed, 43 insertions(+), 98 deletions(-) diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index e7e49825f..5bfee9205 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -8,10 +8,8 @@ namespace Nette\Bridges\FormsLatte; use Latte; -use Latte\CompileException; -use Latte\MacroNode; +use Latte\{CompileException, MacroNode, PhpWriter}; use Latte\Macros\MacroSet; -use Latte\PhpWriter; /** diff --git a/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php b/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php index 90b8ac8a9..18ec02ae1 100644 --- a/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php +++ b/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php @@ -7,18 +7,11 @@ namespace Nette\Bridges\FormsLatte\Nodes; -use Latte\Compiler\Nodes\AreaNode; -use Latte\Compiler\Nodes\AuxiliaryNode; -use Latte\Compiler\Nodes\Html\AttributeNode; -use Latte\Compiler\Nodes\Html\ElementNode; -use Latte\Compiler\Nodes\Html\ExpressionAttributeNode; -use Latte\Compiler\Nodes\NopNode; +use Latte\Compiler\Nodes\{AreaNode, AuxiliaryNode, NopNode, StatementNode, TextNode}; +use Latte\Compiler\Nodes\Html\{AttributeNode, ElementNode, ExpressionAttributeNode}; use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\Php\Scalar\StringNode; -use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\Nodes\TextNode; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/FormContainerNode.php b/src/Bridges/FormsLatte/Nodes/FormContainerNode.php index 01af392c1..c0da3e741 100644 --- a/src/Bridges/FormsLatte/Nodes/FormContainerNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormContainerNode.php @@ -7,11 +7,9 @@ namespace Nette\Bridges\FormsLatte\Nodes; -use Latte\Compiler\Nodes\AreaNode; +use Latte\Compiler\Nodes\{AreaNode, StatementNode}; use Latte\Compiler\Nodes\Php\ExpressionNode; -use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php index f35de2a6e..7e5b34825 100644 --- a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php @@ -8,13 +8,10 @@ namespace Nette\Bridges\FormsLatte\Nodes; use Latte; -use Latte\Compiler\Nodes\AreaNode; -use Latte\Compiler\Nodes\AuxiliaryNode; +use Latte\Compiler\Nodes\{AreaNode, AuxiliaryNode, StatementNode}; use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\Php\Scalar\StringNode; -use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/FormNode.php b/src/Bridges/FormsLatte/Nodes/FormNode.php index 44f50e557..cc3a3e45c 100644 --- a/src/Bridges/FormsLatte/Nodes/FormNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormNode.php @@ -8,14 +8,11 @@ namespace Nette\Bridges\FormsLatte\Nodes; use Latte\CompileException; -use Latte\Compiler\Nodes\AreaNode; +use Latte\Compiler\Nodes\{AreaNode, StatementNode}; use Latte\Compiler\Nodes\Php\Expression\ArrayNode; use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\Php\Scalar\StringNode; -use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\Position; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{Position, PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/FormPrintNode.php b/src/Bridges/FormsLatte/Nodes/FormPrintNode.php index ba939838d..5eaa568af 100644 --- a/src/Bridges/FormsLatte/Nodes/FormPrintNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormPrintNode.php @@ -9,8 +9,7 @@ use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/InputErrorNode.php b/src/Bridges/FormsLatte/Nodes/InputErrorNode.php index 87ee8928b..1e356d24a 100644 --- a/src/Bridges/FormsLatte/Nodes/InputErrorNode.php +++ b/src/Bridges/FormsLatte/Nodes/InputErrorNode.php @@ -9,8 +9,7 @@ use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/InputNode.php b/src/Bridges/FormsLatte/Nodes/InputNode.php index 3ebb1fb7f..c6ea3d46a 100644 --- a/src/Bridges/FormsLatte/Nodes/InputNode.php +++ b/src/Bridges/FormsLatte/Nodes/InputNode.php @@ -11,8 +11,7 @@ use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\Php\Scalar\StringNode; use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{PrintContext, Tag}; /** diff --git a/src/Bridges/FormsLatte/Nodes/LabelNode.php b/src/Bridges/FormsLatte/Nodes/LabelNode.php index 9e969c187..c5d7a18bb 100644 --- a/src/Bridges/FormsLatte/Nodes/LabelNode.php +++ b/src/Bridges/FormsLatte/Nodes/LabelNode.php @@ -8,14 +8,11 @@ namespace Nette\Bridges\FormsLatte\Nodes; use Latte\CompileException; -use Latte\Compiler\Nodes\AreaNode; +use Latte\Compiler\Nodes\{AreaNode, StatementNode}; use Latte\Compiler\Nodes\Php\Expression\ArrayNode; use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\Php\Scalar\StringNode; -use Latte\Compiler\Nodes\StatementNode; -use Latte\Compiler\Position; -use Latte\Compiler\PrintContext; -use Latte\Compiler\Tag; +use Latte\Compiler\{Position, PrintContext, Tag}; /** diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index f97d5948c..ea1bc13e1 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -8,9 +8,7 @@ namespace Nette\Forms\Controls; use Nette; -use Nette\Forms\Control; -use Nette\Forms\Form; -use Nette\Forms\Rules; +use Nette\Forms\{Control, Form, Rules}; use Nette\Utils\Html; use Stringable; use function func_num_args, is_array; diff --git a/src/Forms/Controls/SubmitButton.php b/src/Forms/Controls/SubmitButton.php index 33c760b75..2f0fbb660 100644 --- a/src/Forms/Controls/SubmitButton.php +++ b/src/Forms/Controls/SubmitButton.php @@ -8,8 +8,7 @@ namespace Nette\Forms\Controls; use Nette; -use Nette\Forms\Container; -use Nette\Forms\Control; +use Nette\Forms\{Container, Control}; use Stringable; use function is_string; diff --git a/src/Forms/Form.php b/src/Forms/Form.php index e245f6143..d1957057b 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -8,8 +8,7 @@ namespace Nette\Forms; use Nette; -use Nette\Utils\Arrays; -use Nette\Utils\Html; +use Nette\Utils\{Arrays, Html}; use Stringable; use function count, in_array, is_array, is_scalar, is_string; diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index 2ee331c07..06f1ae185 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -8,9 +8,7 @@ namespace Nette\Forms; use Nette; -use Nette\Utils\Html; -use Nette\Utils\Image; -use Nette\Utils\Strings; +use Nette\Utils\{Html, Image, Strings}; use function is_array, is_scalar, is_string; use const ENT_HTML5, ENT_QUOTES; diff --git a/src/Forms/Rendering/DataClassGenerator.php b/src/Forms/Rendering/DataClassGenerator.php index ef39135de..9d46dc1bb 100644 --- a/src/Forms/Rendering/DataClassGenerator.php +++ b/src/Forms/Rendering/DataClassGenerator.php @@ -7,8 +7,7 @@ namespace Nette\Forms\Rendering; -use Nette\Forms\Blueprint; -use Nette\Forms\Form; +use Nette\Forms\{Blueprint, Form}; /** diff --git a/src/Forms/Rendering/LatteRenderer.php b/src/Forms/Rendering/LatteRenderer.php index 99fff77a1..aee8449cb 100644 --- a/src/Forms/Rendering/LatteRenderer.php +++ b/src/Forms/Rendering/LatteRenderer.php @@ -7,8 +7,7 @@ namespace Nette\Forms\Rendering; -use Nette\Forms\Blueprint; -use Nette\Forms\Form; +use Nette\Forms\{Blueprint, Form}; /** diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index 31f55a825..d4443b81d 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -8,8 +8,7 @@ namespace Nette\Forms; use Nette; -use Nette\Utils\Strings; -use Nette\Utils\Validators; +use Nette\Utils\{Strings, Validators}; use function count, is_array, is_float, is_int, is_object, is_string; diff --git a/tests/Controls/BaseControl.extensionMethod.phpt b/tests/Controls/BaseControl.extensionMethod.phpt index 1f1c654c6..bb9b73ccd 100644 --- a/tests/Controls/BaseControl.extensionMethod.phpt +++ b/tests/Controls/BaseControl.extensionMethod.phpt @@ -1,9 +1,6 @@ Date: Wed, 28 Oct 2026 04:59:11 +0100 Subject: [PATCH 05/18] cs --- examples/basic-example.php | 10 +- examples/bootstrap4-rendering.php | 5 +- examples/bootstrap5-rendering.php | 5 +- examples/containers.php | 5 +- examples/custom-control.php | 5 +- examples/custom-rendering.php | 5 +- examples/custom-validator.php | 5 +- examples/html5.php | 5 +- examples/latte.php | 5 +- examples/live-validation.php | 5 +- examples/localization.php | 5 +- examples/manual-rendering.php | 5 +- src/Bridges/FormsLatte/FormMacros.php | 22 ++-- src/Bridges/FormsLatte/Runtime.php | 10 +- src/Forms/Blueprint.php | 10 +- src/Forms/Container.php | 7 +- src/Forms/Control.php | 1 - src/Forms/Controls/BaseControl.php | 13 ++- src/Forms/Controls/Checkbox.php | 8 +- src/Forms/Controls/CheckboxList.php | 5 +- src/Forms/Controls/ChoiceControl.php | 6 +- src/Forms/Controls/CsrfProtection.php | 4 +- src/Forms/Controls/DateTimeControl.php | 12 +- src/Forms/Controls/HiddenField.php | 8 +- src/Forms/Controls/MultiChoiceControl.php | 20 +++- src/Forms/Controls/RadioList.php | 5 +- src/Forms/Controls/SelectBox.php | 4 +- src/Forms/Controls/TextBase.php | 9 +- src/Forms/Controls/UploadControl.php | 2 +- src/Forms/Form.php | 3 +- src/Forms/Helpers.php | 1 + src/Forms/Rendering/DefaultFormRenderer.php | 2 +- src/Forms/Validator.php | 5 +- .../Controls/BaseControl.extensionMethod.phpt | 1 - tests/Controls/BaseControl.phpt | 1 - tests/Controls/Button.loadData.phpt | 1 - tests/Controls/Button.render.phpt | 16 ++- tests/Controls/Checkbox.loadData.phpt | 1 - tests/Controls/Checkbox.render.phpt | 11 +- tests/Controls/CheckboxList.loadData.phpt | 1 - tests/Controls/CheckboxList.render.phpt | 43 ++++++-- tests/Controls/ChoiceControl.loadData.phpt | 3 +- tests/Controls/Controls.translate().phpt | 21 ++-- .../Controls/CsrfProtection.breachAttack.phpt | 1 - tests/Controls/CsrfProtection.phpt | 10 +- tests/Controls/DateTimeControl.format.phpt | 1 - tests/Controls/DateTimeControl.loadData.phpt | 1 - tests/Controls/DateTimeControl.render.phpt | 31 ++++-- tests/Controls/DateTimeControl.value.phpt | 1 - tests/Controls/HiddenField.loadData.phpt | 1 - tests/Controls/HiddenField.render.phpt | 1 - tests/Controls/ImageButton.loadData.phpt | 1 - tests/Controls/ImageButton.render.phpt | 1 - .../Controls/MultiChoiceControl.loadData.phpt | 1 - tests/Controls/MultiSelectBox.loadData.phpt | 1 - tests/Controls/MultiSelectBox.render.phpt | 53 +++++++-- tests/Controls/RadioList.loadData.phpt | 1 - tests/Controls/RadioList.render.phpt | 48 ++++++-- tests/Controls/SelectBox.isOk.phpt | 3 +- tests/Controls/SelectBox.loadData.phpt | 1 - tests/Controls/SelectBox.render.phpt | 103 ++++++++++++++---- tests/Controls/TestBase.validators.phpt | 3 +- tests/Controls/TextArea.render.phpt | 11 +- tests/Controls/TextBase.loadData.phpt | 9 +- tests/Controls/TextInput.render.phpt | 85 ++++++++++++--- .../TextInput.valueObjectValidation.phpt | 10 +- tests/Controls/UploadControl.loadData.phpt | 1 - tests/Controls/UploadControl.render.phpt | 26 ++++- tests/Forms.DI/FormsExtension.phpt | 1 - tests/Forms.Latte3/forms.phpt | 2 +- tests/Forms/Blueprint.dataClass.phpt | 1 - tests/Forms/Blueprint.latte.phpt | 1 - tests/Forms/Container.extensionMethod.phpt | 1 - tests/Forms/Container.validate().phpt | 1 - tests/Forms/Container.values.ArrayHash.phpt | 1 - tests/Forms/Container.values.array.phpt | 1 - .../Container.values.mapping-constructor.phpt | 3 - .../Forms/Container.values.mapping-enum.phpt | 1 - tests/Forms/Container.values.mapping.phpt | 1 - tests/Forms/ControlGroup.phpt | 5 +- tests/Forms/Forms.crossOrigin.phpt | 1 - tests/Forms/Forms.getHttpData.get.2.phpt | 1 - tests/Forms/Forms.getHttpData.get.phpt | 1 - tests/Forms/Forms.getHttpData.post.phpt | 1 - tests/Forms/Forms.idMask.phpt | 1 - tests/Forms/Forms.isValid.phpt | 1 - tests/Forms/Forms.maxPostSize.phpt | 1 - tests/Forms/Forms.no.events.phpt | 1 - tests/Forms/Forms.omittedValue.phpt | 1 - tests/Forms/Forms.onClick.phpt | 1 - tests/Forms/Forms.onRender.phpt | 1 - tests/Forms/Forms.onSuccess.phpt | 1 - tests/Forms/Forms.renderer.1.phpt | 21 +++- tests/Forms/Forms.renderer.2.phpt | 15 ++- tests/Forms/Forms.renderer.5.phpt | 2 +- tests/Forms/Forms.renderer.translate.phpt | 2 +- tests/Forms/Forms.submittedBy.phpt | 1 - tests/Forms/Forms.toggle.phpt | 1 - tests/Forms/Forms.userValidator.phpt | 7 +- tests/Forms/Forms.validationScope.phpt | 1 - tests/Forms/Helpers.createInputList.phpt | 3 +- tests/Forms/Helpers.createSelectBox.phpt | 1 - tests/Forms/Helpers.exportRules.phpt | 5 +- tests/Forms/Helpers.extractHttpData.phpt | 6 +- tests/Forms/Helpers.generateHtmlName.phpt | 1 - tests/Forms/Rules.dynamic.phpt | 1 - tests/Forms/Rules.formatMessage.phpt | 1 - tests/Forms/Rules.removeRule.phpt | 1 - tests/Forms/Rules.required.phpt | 5 +- tests/Forms/Rules.reset.phpt | 1 - tests/Forms/Rules.static.phpt | 1 - tests/Forms/Rules.valid.phpt | 5 +- tests/bootstrap.php | 2 +- tests/types/forms-types.php | 2 +- 114 files changed, 542 insertions(+), 300 deletions(-) diff --git a/examples/basic-example.php b/examples/basic-example.php index 5d3654e77..f60c352a1 100644 --- a/examples/basic-example.php +++ b/examples/basic-example.php @@ -5,14 +5,13 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; use Nette\Utils\Html; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); @@ -21,7 +20,10 @@ // group Personal data $form->addGroup('Personal data') - ->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.'); + ->setOption( + 'description', + 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.', + ); $form->addText('name', 'Your name:') ->setRequired('Enter your name'); diff --git a/examples/bootstrap4-rendering.php b/examples/bootstrap4-rendering.php index a674674a1..c2374b14b 100644 --- a/examples/bootstrap4-rendering.php +++ b/examples/bootstrap4-rendering.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/bootstrap5-rendering.php b/examples/bootstrap5-rendering.php index 22065e221..68db86ff0 100644 --- a/examples/bootstrap5-rendering.php +++ b/examples/bootstrap5-rendering.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/containers.php b/examples/containers.php index 6537cb6e0..e323d4d60 100644 --- a/examples/containers.php +++ b/examples/containers.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/custom-control.php b/examples/custom-control.php index c02fc6960..aa407f339 100644 --- a/examples/custom-control.php +++ b/examples/custom-control.php @@ -5,12 +5,11 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } -use Nette\Forms\Form; -use Nette\Forms\Helpers; +use Nette\Forms\{Form, Helpers}; use Nette\Utils\Html; diff --git a/examples/custom-rendering.php b/examples/custom-rendering.php index 8ae60f8e4..129928c5f 100644 --- a/examples/custom-rendering.php +++ b/examples/custom-rendering.php @@ -5,14 +5,13 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; use Nette\Utils\Html; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/custom-validator.php b/examples/custom-validator.php index d27df2f8d..9af0c1d42 100644 --- a/examples/custom-validator.php +++ b/examples/custom-validator.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/html5.php b/examples/html5.php index 2c8f43628..da1f8d0c1 100644 --- a/examples/html5.php +++ b/examples/html5.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/latte.php b/examples/latte.php index 256e4e4fd..271679192 100644 --- a/examples/latte.php +++ b/examples/latte.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/live-validation.php b/examples/live-validation.php index 8ebd3a518..fb83f41e2 100644 --- a/examples/live-validation.php +++ b/examples/live-validation.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/localization.php b/examples/localization.php index 876f64f5c..9523d080f 100644 --- a/examples/localization.php +++ b/examples/localization.php @@ -5,14 +5,13 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/examples/manual-rendering.php b/examples/manual-rendering.php index 6c54f7cfe..28cdd5466 100644 --- a/examples/manual-rendering.php +++ b/examples/manual-rendering.php @@ -5,13 +5,12 @@ */ -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed die('Install packages using `composer install`'); } use Nette\Forms\Form; -use Tracy\Debugger; -use Tracy\Dumper; +use Tracy\{Debugger, Dumper}; Debugger::enable(); diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index 5bfee9205..cc8bbbfdf 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -27,9 +27,17 @@ final class FormMacros extends MacroSet public static function install(Latte\Compiler $compiler): void { $me = new static($compiler); - $me->addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack));'); + $me->addMacro( + 'form', + [$me, 'macroForm'], + 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack));', + ); $me->addMacro('formContext', [$me, 'macroFormContext'], 'array_pop($this->global->formsStack);'); - $me->addMacro('formContainer', [$me, 'macroFormContainer'], 'array_pop($this->global->formsStack); $formContainer = end($this->global->formsStack)'); + $me->addMacro( + 'formContainer', + [$me, 'macroFormContainer'], + 'array_pop($this->global->formsStack); $formContainer = end($this->global->formsStack)', + ); $me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd'], null, self::AUTO_EMPTY); $me->addMacro('input', [$me, 'macroInput']); $me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']); @@ -56,7 +64,7 @@ public function macroForm(MacroNode $node, PhpWriter $writer) } $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false + if ($name == null) { // intentionally ==, null or false throw new CompileException('Missing form name in ' . $node->getNotation()); } @@ -89,7 +97,7 @@ public function macroFormContext(MacroNode $node, PhpWriter $writer) } $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false + if ($name == null) { // intentionally ==, null or false throw new CompileException('Missing form name in ' . $node->getNotation()); } @@ -114,7 +122,7 @@ public function macroFormContainer(MacroNode $node, PhpWriter $writer) } $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false + if ($name == null) { // intentionally ==, null or false throw new CompileException('Missing name in ' . $node->getNotation()); } @@ -163,7 +171,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer) */ public function macroLabelEnd(MacroNode $node, PhpWriter $writer) { - if ($node->content != null) { + if ($node->content != null) { // intentionally != $node->openingCode = rtrim($node->openingCode, '?> ') . '->startTag() ?>'; return $writer->write('if ($ʟ_label) echo $ʟ_label->endTag()'); } @@ -312,7 +320,7 @@ public function macroInputError(MacroNode $node, PhpWriter $writer) public function macroFormPrint(MacroNode $node, PhpWriter $writer) { $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false + if ($name == null) { // intentionally ==, null or false throw new CompileException('Missing form name in ' . $node->getNotation()); } diff --git a/src/Bridges/FormsLatte/Runtime.php b/src/Bridges/FormsLatte/Runtime.php index f7225365b..16561a393 100644 --- a/src/Bridges/FormsLatte/Runtime.php +++ b/src/Bridges/FormsLatte/Runtime.php @@ -58,7 +58,12 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string { $s = ''; if ($form->isMethod('get')) { - foreach (preg_split('#[;&]#', (string) parse_url((string) $form->getElementPrototype()->action, PHP_URL_QUERY), -1, PREG_SPLIT_NO_EMPTY) as $param) { + foreach (preg_split( + '#[;&]#', + (string) parse_url((string) $form->getElementPrototype()->action, PHP_URL_QUERY), + -1, + PREG_SPLIT_NO_EMPTY, + ) as $param) { $parts = explode('=', $param, 2); $name = urldecode($parts[0]); $prefix = explode('[', $name, 2)[0]; @@ -87,7 +92,8 @@ public static function item(object|string|int $item, object $global): object if (is_object($item)) { return $item; } - $form = end($global->formsStack) ?: throw new \LogicException('Form declaration is missing, did you use {form} or
tag?'); + $form = end($global->formsStack) + ?: throw new \LogicException('Form declaration is missing, did you use {form} or tag?'); return $form[$item]; } } diff --git a/src/Forms/Blueprint.php b/src/Forms/Blueprint.php index 13f2ed87a..2727eced2 100644 --- a/src/Forms/Blueprint.php +++ b/src/Forms/Blueprint.php @@ -148,8 +148,10 @@ public function getOption(mixed $key): mixed if ($renderer instanceof Rendering\DefaultFormRenderer) { $renderer->wrappers['error']['container'] = $renderer->getWrapper('error container')->setAttribute('n:ifcontent', true); - $renderer->wrappers['error']['item'] = $renderer->getWrapper('error item')->setAttribute('n:foreach', '$form->getOwnErrors() as $error'); - $renderer->wrappers['control']['errorcontainer'] = $renderer->getWrapper('control errorcontainer')->setAttribute('n:ifcontent', true); + $renderer->wrappers['error']['item'] = $renderer->getWrapper('error item') + ->setAttribute('n:foreach', '$form->getOwnErrors() as $error'); + $renderer->wrappers['control']['errorcontainer'] = $renderer->getWrapper('control errorcontainer') + ->setAttribute('n:ifcontent', true); $dummyForm->addError('{$error}'); ob_start(); @@ -221,8 +223,8 @@ public function generateDataClass( . "{\n" . ($propertyPromotion ? "\tpublic function __construct(\n" - . ($props ? "\t\t" . implode(",\n\t\t", $props) . ",\n" : '') - . "\t) {\n\t}\n" + . ($props ? "\t\t" . implode(",\n\t\t", $props) . ",\n" : '') + . "\t) {\n\t}\n" : ($props ? "\t" . implode(";\n\t", $props) . ";\n" : '') ) . "}\n\n" diff --git a/src/Forms/Container.php b/src/Forms/Container.php index b9030d903..a57706cb1 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -259,7 +259,7 @@ public function getErrors(): array { $errors = []; foreach ($this->getControls() as $control) { - $errors = array_merge($errors, $control->getErrors()); + $errors = [...$errors, ...$control->getErrors()]; } return array_values(array_unique($errors)); @@ -369,7 +369,8 @@ public function addTextArea( ): Controls\TextArea { return $this[$name] = (new Controls\TextArea($label)) - ->setHtmlAttribute('cols', $cols)->setHtmlAttribute('rows', $rows); + ->setHtmlAttribute('cols', $cols) + ->setHtmlAttribute('rows', $rows); } @@ -451,7 +452,7 @@ public function addDateTime( */ public function addUpload(string $name, string|Stringable|null $label = null): Controls\UploadControl { - return $this[$name] = new Controls\UploadControl($label, multiple: false); + return $this[$name] = new Controls\UploadControl($label); } diff --git a/src/Forms/Control.php b/src/Forms/Control.php index 3ec1f2d00..7eafdd111 100644 --- a/src/Forms/Control.php +++ b/src/Forms/Control.php @@ -14,7 +14,6 @@ interface Control { /** - * @param mixed $value * @return static */ function setValue(mixed $value); diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index ea1bc13e1..a97ade484 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -47,7 +47,6 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con /** @var array> */ private static array $extMethods = []; - private string|Stringable|null $caption; /** @var list */ private array $errors = []; @@ -61,11 +60,11 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con private array $options = []; - public function __construct(string|Stringable|null $caption = null) - { + public function __construct( + private string|Stringable|null $caption = null, + ) { $this->control = Html::el('input', ['type' => null, 'name' => null]); $this->label = Html::el('label'); - $this->caption = $caption; $this->rules = new Rules($this); $this->setValue(null); $this->monitor(Form::class, function (Form $form): void { @@ -248,7 +247,9 @@ public function getLabel(string|Stringable|null $caption = null) $label->for = $this->getHtmlId(); $caption ??= $this->caption; $translator = $this->getForm()->getTranslator(); - $label->setText($translator && $caption !== null && !$caption instanceof Nette\HtmlStringable ? $translator->translate($caption) : $caption); + $label->setText( + $translator && $caption !== null && !$caption instanceof Nette\HtmlStringable ? $translator->translate($caption) : $caption, + ); return $label; } @@ -367,7 +368,7 @@ public function getTranslator(): ?Nette\Localization\Translator /** - * Translates a string or array of strings using the configured translator, or returns the value unchanged if no translator is set or the value is HtmlStringable. + * Translates a string or array of strings, or returns the value unchanged without a translator or when it is HtmlStringable. */ public function translate(mixed $value, mixed ...$parameters): mixed { diff --git a/src/Forms/Controls/Checkbox.php b/src/Forms/Controls/Checkbox.php index 437a1490d..080dfe0d7 100644 --- a/src/Forms/Controls/Checkbox.php +++ b/src/Forms/Controls/Checkbox.php @@ -34,10 +34,14 @@ public function __construct(string|Stringable|null $label = null) * @return static * @internal */ - public function setValue($value) + public function setValue(mixed $value) { if (!is_scalar($value) && $value !== null) { - throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", get_debug_type($value), $this->getName())); + throw new Nette\InvalidArgumentException(sprintf( + "Value must be scalar or null, %s given in field '%s'.", + get_debug_type($value), + $this->getName(), + )); } $this->value = (bool) $value; diff --git a/src/Forms/Controls/CheckboxList.php b/src/Forms/Controls/CheckboxList.php index eb807267b..454c2091b 100644 --- a/src/Forms/Controls/CheckboxList.php +++ b/src/Forms/Controls/CheckboxList.php @@ -61,13 +61,14 @@ public function getControl(): Html return $this->container->setHtml( Nette\Forms\Helpers::createInputList( $this->translate($items), - array_merge($input->attrs, [ + [ + ...$input->attrs, 'id' => null, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'required' => null, 'data-nette-rules:' => [array_key_first($items) => $input->attrs['data-nette-rules']], - ]), + ], $this->itemLabel->attrs, $this->separator, ), diff --git a/src/Forms/Controls/ChoiceControl.php b/src/Forms/Controls/ChoiceControl.php index b45baacbd..0395926c3 100644 --- a/src/Forms/Controls/ChoiceControl.php +++ b/src/Forms/Controls/ChoiceControl.php @@ -56,7 +56,11 @@ public function setValue($value) } if ($this->checkDefaultValue && $value !== null && !array_key_exists((string) $value, $this->items)) { - $set = Nette\Utils\Strings::truncate(implode(', ', array_map(fn($s) => var_export($s, return: true), array_keys($this->items))), 70, '...'); + $set = Nette\Utils\Strings::truncate( + implode(', ', array_map(fn($s) => var_export($s, return: true), array_keys($this->items))), + 70, + '...', + ); throw new Nette\InvalidArgumentException("Value '$value' is out of allowed set [$set] in field '{$this->getName()}'."); } diff --git a/src/Forms/Controls/CsrfProtection.php b/src/Forms/Controls/CsrfProtection.php index 7a89456ef..768d16b23 100644 --- a/src/Forms/Controls/CsrfProtection.php +++ b/src/Forms/Controls/CsrfProtection.php @@ -53,7 +53,7 @@ public function __construct(string|Stringable|null $errorMessage = null) /** * @internal */ - public function setValue($value): static + public function setValue(mixed $value): static { return $this; } @@ -82,7 +82,7 @@ public function getToken(): string private function generateToken(?string $random = null): string { - $random ??= Nette\Utils\Random::generate(10); + $random ??= Nette\Utils\Random::generate(); return $random . base64_encode(sha1($this->getToken() . $random, binary: true)); } diff --git a/src/Forms/Controls/DateTimeControl.php b/src/Forms/Controls/DateTimeControl.php index 1547e8dc8..27428e993 100644 --- a/src/Forms/Controls/DateTimeControl.php +++ b/src/Forms/Controls/DateTimeControl.php @@ -29,11 +29,9 @@ class DateTimeControl extends BaseControl private string $format = self::FormatObject; - /** - * @param self::TypeDate|self::TypeTime|self::TypeDateTime $type - */ public function __construct( string|Stringable|null $label = null, + /** @var self::TypeDate|self::TypeTime|self::TypeDateTime */ private readonly int $type = self::TypeDate, private readonly bool $withSeconds = false, ) { @@ -112,7 +110,9 @@ public function getControl(): Nette\Utils\Html ...$this->getAttributesFromRules(), 'value' => $this->value ? $this->formatHtmlValue($this->value) : null, 'type' => match ($this->type) { - self::TypeDate => 'date', self::TypeTime => 'time', self::TypeDateTime => 'datetime-local' + self::TypeDate => 'date', + self::TypeTime => 'time', + self::TypeDateTime => 'datetime-local', }, ]); } @@ -149,8 +149,8 @@ private function getAttributesFromRules(): array { $attrs = []; $format = fn($val) => is_scalar($val) || $val instanceof \DateTimeInterface - ? $this->formatHtmlValue($val) - : null; + ? $this->formatHtmlValue($val) + : null; foreach ($this->getRules() as $rule) { if ($rule->branch) { } elseif (!$rule->canExport()) { diff --git a/src/Forms/Controls/HiddenField.php b/src/Forms/Controls/HiddenField.php index 87c589687..d72fb03db 100644 --- a/src/Forms/Controls/HiddenField.php +++ b/src/Forms/Controls/HiddenField.php @@ -40,14 +40,18 @@ public function __construct(mixed $persistentValue = null) * @return static * @internal */ - public function setValue($value) + public function setValue(mixed $value) { if ($value === null) { $value = ''; } elseif ($value instanceof \BackedEnum) { $value = $value->value; } elseif (!is_scalar($value) && !$value instanceof Stringable) { - throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", get_debug_type($value), $this->getName())); + throw new Nette\InvalidArgumentException(sprintf( + "Value must be scalar or null, %s given in field '%s'.", + get_debug_type($value), + $this->getName(), + )); } if (!$this->persistValue) { diff --git a/src/Forms/Controls/MultiChoiceControl.php b/src/Forms/Controls/MultiChoiceControl.php index 9d1a69dff..f509724be 100644 --- a/src/Forms/Controls/MultiChoiceControl.php +++ b/src/Forms/Controls/MultiChoiceControl.php @@ -46,12 +46,16 @@ public function loadHttpData(): void * @return static * @internal */ - public function setValue($values) + public function setValue(mixed $values) { if (is_scalar($values) || $values === null) { $values = (array) $values; } elseif (!is_array($values)) { - throw new Nette\InvalidArgumentException(sprintf("Value must be array or null, %s given in field '%s'.", get_debug_type($values), $this->getName())); + throw new Nette\InvalidArgumentException(sprintf( + "Value must be array or null, %s given in field '%s'.", + get_debug_type($values), + $this->getName(), + )); } $flip = []; @@ -59,7 +63,11 @@ public function setValue($values) if ($value instanceof \BackedEnum) { $value = $value->value; } elseif (!is_scalar($value) && !$value instanceof \Stringable) { - throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", get_debug_type($value), $this->getName())); + throw new Nette\InvalidArgumentException(sprintf( + "Values must be scalar, %s given in field '%s'.", + get_debug_type($value), + $this->getName(), + )); } $flip[(string) $value] = true; @@ -67,7 +75,11 @@ public function setValue($values) $values = array_keys($flip); if ($this->checkDefaultValue && ($diff = array_diff($values, array_keys($this->items)))) { - $set = Nette\Utils\Strings::truncate(implode(', ', array_map(fn($s) => var_export($s, return: true), array_keys($this->items))), 70, '...'); + $set = Nette\Utils\Strings::truncate( + implode(', ', array_map(fn($s) => var_export($s, return: true), array_keys($this->items))), + 70, + '...', + ); $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'"; throw new Nette\InvalidArgumentException("Value$vals are out of allowed set [$set] in field '{$this->getName()}'."); } diff --git a/src/Forms/Controls/RadioList.php b/src/Forms/Controls/RadioList.php index 1369ae073..e7425f8db 100644 --- a/src/Forms/Controls/RadioList.php +++ b/src/Forms/Controls/RadioList.php @@ -57,12 +57,13 @@ public function getControl(): Html return $this->container->setHtml( Nette\Forms\Helpers::createInputList( $this->translate($items), - array_merge($input->attrs, [ + [ + ...$input->attrs, 'id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'data-nette-rules:' => [array_key_first($items) => $input->attrs['data-nette-rules']], - ]), + ], ['for:' => $ids] + $this->itemLabel->attrs, $this->separator, ), diff --git a/src/Forms/Controls/SelectBox.php b/src/Forms/Controls/SelectBox.php index ed12cbd90..b8a2eb67d 100644 --- a/src/Forms/Controls/SelectBox.php +++ b/src/Forms/Controls/SelectBox.php @@ -38,8 +38,8 @@ public function __construct(string|Stringable|null $label = null, ?array $items $this->setOption('type', 'select'); $this->addCondition( fn() => $this->prompt === false - && $this->options - && $this->control->size < 2, + && $this->options + && $this->control->size < 2, )->addRule(Nette\Forms\Form::Filled, Nette\Forms\Validator::$messages[self::Valid]); } diff --git a/src/Forms/Controls/TextBase.php b/src/Forms/Controls/TextBase.php index 66b226fe8..c13cebb96 100644 --- a/src/Forms/Controls/TextBase.php +++ b/src/Forms/Controls/TextBase.php @@ -28,12 +28,16 @@ abstract class TextBase extends BaseControl * @return static * @internal */ - public function setValue($value) + public function setValue(mixed $value) { if ($value === null) { $value = ''; } elseif (!is_scalar($value) && !$value instanceof Stringable) { - throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", get_debug_type($value), $this->getName())); + throw new Nette\InvalidArgumentException(sprintf( + "Value must be scalar or null, %s given in field '%s'.", + get_debug_type($value), + $this->getName(), + )); } $this->value = $value; @@ -44,7 +48,6 @@ public function setValue($value) /** * Returns the value, substituting empty string when it matches the empty value. Returns null when nullable is set and value is empty. - * @return mixed */ public function getValue(): mixed { diff --git a/src/Forms/Controls/UploadControl.php b/src/Forms/Controls/UploadControl.php index 997639b01..d7728e22e 100644 --- a/src/Forms/Controls/UploadControl.php +++ b/src/Forms/Controls/UploadControl.php @@ -69,7 +69,7 @@ public function getHtmlName(): string * @return static * @internal */ - public function setValue($value) + public function setValue(mixed $value) { return $this; } diff --git a/src/Forms/Form.php b/src/Forms/Form.php index d1957057b..ff8d61d23 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -558,6 +558,7 @@ protected function receiveHttpData(): ?array } $data = Nette\Utils\Arrays::mergeTree($httpRequest->getPost(), $httpRequest->getFiles()); + } else { $data = $httpRequest->getQuery(); if (!$data) { @@ -624,7 +625,7 @@ public function addError(string|Stringable $message, bool $translate = true): vo */ public function getErrors(): array { - return array_values(array_unique(array_merge($this->errors, parent::getErrors()))); + return array_values(array_unique([...$this->errors, ...parent::getErrors()])); } diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index 06f1ae185..b4fcf04bf 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -60,6 +60,7 @@ public static function extractHttpData( } return array_values($data); + } else { return static::sanitize($itype, $data); } diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index d9237aaf5..d2a05d7e2 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -485,7 +485,7 @@ public function renderControl(Nette\Forms\Control $control): Html } $els[] = $el; - $errors = array_merge($errors, $control->getErrors()); + $errors = [...$errors, ...$control->getErrors()]; if ($nextTo = $control->getOption('nextTo')) { $control = $control->getForm()->getComponent($nextTo); diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index d4443b81d..d6de0ee71 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -86,9 +86,10 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string } return ''; + case 'value': return $withValue - ? $rule->control->getValue() - : $m[0]; + ? $rule->control->getValue() + : $m[0]; default: $args = is_array($rule->arg) ? $rule->arg : [$rule->arg]; $i = (int) $m[1] ? (int) $m[1] - 1 : $i + 1; diff --git a/tests/Controls/BaseControl.extensionMethod.phpt b/tests/Controls/BaseControl.extensionMethod.phpt index bb9b73ccd..2eff56ab6 100644 --- a/tests/Controls/BaseControl.extensionMethod.phpt +++ b/tests/Controls/BaseControl.extensionMethod.phpt @@ -3,7 +3,6 @@ use Nette\Forms\Controls\{Button, Checkbox, TextBase, TextInput}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/BaseControl.phpt b/tests/Controls/BaseControl.phpt index d697777f8..2fa5041f4 100644 --- a/tests/Controls/BaseControl.phpt +++ b/tests/Controls/BaseControl.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Form, Validator}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/Button.loadData.phpt b/tests/Controls/Button.loadData.phpt index c2ad1f225..1a344bbf2 100644 --- a/tests/Controls/Button.loadData.phpt +++ b/tests/Controls/Button.loadData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/Button.render.phpt b/tests/Controls/Button.render.phpt index 31dc11655..8c70c0ee2 100644 --- a/tests/Controls/Button.render.phpt +++ b/tests/Controls/Button.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -48,7 +47,10 @@ test('button with HTML content', function () { Assert::same('', (string) $input->getControl()); Assert::same('', (string) $input->getControl('Another caption')); - Assert::same('', (string) $input->getControl(Html::el('b', 'Another label'))); + Assert::same( + '', + (string) $input->getControl(Html::el('b', 'Another label')), + ); }); @@ -68,7 +70,10 @@ test('HTML content in button with translator', function () { $input->setTranslator(new Translator); Assert::same('', (string) $input->getControl()); - Assert::same('', (string) $input->getControl(Html::el('b', 'Another label'))); + Assert::same( + '', + (string) $input->getControl(Html::el('b', 'Another label')), + ); }); @@ -114,7 +119,10 @@ test('validation scope with specified fields', function () { $select = $form->addSelect('select'); $input = $form->addSubmit('button', 'Caption')->setValidationScope([$text, $select]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/Checkbox.loadData.phpt b/tests/Controls/Checkbox.loadData.phpt index c9039cc9c..a277e6960 100644 --- a/tests/Controls/Checkbox.loadData.phpt +++ b/tests/Controls/Checkbox.loadData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/Checkbox.render.phpt b/tests/Controls/Checkbox.render.phpt index 6bb5bb6bd..bc09003a5 100644 --- a/tests/Controls/Checkbox.render.phpt +++ b/tests/Controls/Checkbox.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -55,7 +54,10 @@ test('required checkbox attributes', function () { $form = new Form; $input = $form->addCheckbox('on')->setRequired('required'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -64,7 +66,10 @@ test('checkbox within container naming', function () { $container = $form->addContainer('container'); $input = $container->addCheckbox('on'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/CheckboxList.loadData.phpt b/tests/Controls/CheckboxList.loadData.phpt index f604f5ba9..1f223d9c4 100644 --- a/tests/Controls/CheckboxList.loadData.phpt +++ b/tests/Controls/CheckboxList.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\{Form, Validator}; use Nette\Utils\DateTime; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/CheckboxList.render.phpt b/tests/Controls/CheckboxList.render.phpt index 63db12c5b..e0981fa77 100644 --- a/tests/Controls/CheckboxList.render.phpt +++ b/tests/Controls/CheckboxList.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -36,7 +35,10 @@ test('checkbox list HTML structure', function () { Assert::same('', (string) $input->getLabelPart(0)); Assert::type(Html::class, $input->getControl()); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); Assert::type(Html::class, $input->getControlPart(0)); Assert::same('', (string) $input->getControlPart(0)); @@ -50,7 +52,10 @@ test('pre-selected checkbox rendering', function () { 0 => 'Second', ])->setValue(0); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); @@ -66,7 +71,10 @@ test('translator affects item labels', function () { Assert::same('', (string) $input->getLabel('Another label')); Assert::same('', (string) $input->getLabelPart(0)); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); Assert::same('', (string) $input->getControlPart(0)); }); @@ -93,8 +101,14 @@ test('required checkbox list attributes', function () { 0 => 'Second', ])->setRequired('required'); - Assert::same('
', (string) $input->getControl()); - Assert::same('', (string) $input->getControlPart(0)); + Assert::same( + '
', + (string) $input->getControl(), + ); + Assert::same( + '', + (string) $input->getControlPart(0), + ); }); @@ -106,7 +120,10 @@ test('checkbox list within container', function () { 0 => 'Second', ]); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); @@ -126,9 +143,12 @@ test('entire list disabled', function () { $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ])->setDisabled(true); + ])->setDisabled(); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); @@ -139,7 +159,10 @@ test('selective item disabling', function () { 0 => 'Second', ])->setDisabled(['a']); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); Assert::same('', (string) $input->getControlPart('a')); }); diff --git a/tests/Controls/ChoiceControl.loadData.phpt b/tests/Controls/ChoiceControl.loadData.phpt index 98b96036d..9a4458102 100644 --- a/tests/Controls/ChoiceControl.loadData.phpt +++ b/tests/Controls/ChoiceControl.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\DateTime; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -213,7 +212,7 @@ test('items with null labels', function () { $form = new Form; $form->allowCrossOrigin(); - $input = $form['select'] = new ChoiceControl(null); + $input = $form['select'] = new ChoiceControl; $input->setItems([ 1 => null, 2 => 'Red dwarf', diff --git a/tests/Controls/Controls.translate().phpt b/tests/Controls/Controls.translate().phpt index 0e0c81d83..0c87f13ba 100644 --- a/tests/Controls/Controls.translate().phpt +++ b/tests/Controls/Controls.translate().phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -21,12 +20,9 @@ class Translator implements Nette\Localization\ITranslator class StringWrapper { - public $message; - - - public function __construct($message) - { - $this->message = $message; + public function __construct( + public $message, + ) { } @@ -37,7 +33,6 @@ class StringWrapper } - test('translating labels with objects', function () { $form = new Form; $form->setTranslator(new Translator); @@ -87,7 +82,10 @@ test('validation messages with objects', function () { ->setRequired('error') ->addRule($form::Email, 'error'); - Assert::match('', (string) $email->getControl()); + Assert::match( + '', + (string) $email->getControl(), + ); $email->validate(); Assert::same(['error'], $email->getErrors()); @@ -95,7 +93,10 @@ test('validation messages with objects', function () { ->setRequired(new StringWrapper('Your name')) ->addRule($form::Email, new StringWrapper('Your name')); - Assert::match('', (string) $email2->getControl()); + Assert::match( + '', + (string) $email2->getControl(), + ); $email2->validate(); Assert::same(['StringWrapper'], $email2->getErrors()); }); diff --git a/tests/Controls/CsrfProtection.breachAttack.phpt b/tests/Controls/CsrfProtection.breachAttack.phpt index 6e34f6927..78b6f45f7 100644 --- a/tests/Controls/CsrfProtection.breachAttack.phpt +++ b/tests/Controls/CsrfProtection.breachAttack.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/CsrfProtection.phpt b/tests/Controls/CsrfProtection.phpt index 976dfc29e..6425e4353 100644 --- a/tests/Controls/CsrfProtection.phpt +++ b/tests/Controls/CsrfProtection.phpt @@ -4,11 +4,10 @@ * Test: Nette\Forms\Controls\CsrfProtection. */ -use Nette\Forms\Controls\CsrfProtection; +use Nette\Forms\Controls\{BaseControl, CsrfProtection}; use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -31,15 +30,16 @@ Assert::same('hidden', $input->getOption('type')); $input->setValue(null); Assert::false(CsrfProtection::validateCsrf($input)); -@call_user_func([$input, 'Nette\Forms\Controls\BaseControl::setValue'], '12345678901234567890123456789012345678'); // deprecated since PHP 8.2 +$setValue = new ReflectionMethod(BaseControl::class, 'setValue'); +$setValue->invoke($input, '12345678901234567890123456789012345678'); Assert::false(CsrfProtection::validateCsrf($input)); $value = $input->getControl()->value; -@call_user_func([$input, 'Nette\Forms\Controls\BaseControl::setValue'], $value); // deprecated since PHP 8.2 +$setValue->invoke($input, $value); Assert::true(CsrfProtection::validateCsrf($input)); session_regenerate_id(); -@call_user_func([$input, 'Nette\Forms\Controls\BaseControl::setValue'], $value); // deprecated since PHP 8.2 +$setValue->invoke($input, $value); Assert::false(CsrfProtection::validateCsrf($input)); diff --git a/tests/Controls/DateTimeControl.format.phpt b/tests/Controls/DateTimeControl.format.phpt index 713ac12bc..726cc94b3 100644 --- a/tests/Controls/DateTimeControl.format.phpt +++ b/tests/Controls/DateTimeControl.format.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Controls\DateTimeControl; use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/DateTimeControl.loadData.phpt b/tests/Controls/DateTimeControl.loadData.phpt index f228f0746..27c58e34c 100644 --- a/tests/Controls/DateTimeControl.loadData.phpt +++ b/tests/Controls/DateTimeControl.loadData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/DateTimeControl.render.phpt b/tests/Controls/DateTimeControl.render.phpt index 09ea9db54..86df07309 100644 --- a/tests/Controls/DateTimeControl.render.phpt +++ b/tests/Controls/DateTimeControl.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -25,7 +24,10 @@ test('required date input attributes', function () { $form = new Form; $input = $form->addDate('date')->setRequired('required'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -35,7 +37,10 @@ test('date min/max attributes', function () { ->addRule($form::Min, null, new DateTime('2020-01-01 11:22:33')) ->addRule($form::Max, null, new DateTime('2040-01-01 11:22:33')); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); @@ -44,7 +49,10 @@ test('date range attributes', function () { $input = $form->addDate('date') ->addRule($form::Range, null, [new DateTime('2020-01-01 11:22:33'), new DateTime('2040-01-01 22:33:44')]); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); @@ -53,7 +61,10 @@ test('time range attributes', function () { $input = $form->addTime('time') ->addRule($form::Range, null, [new DateTime('2020-01-01 11:22:33'), new DateTime('2040-01-01 22:33:44')]); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); @@ -62,7 +73,10 @@ test('time with seconds range', function () { $input = $form->addTime('time', withSeconds: true) ->addRule($form::Range, null, [new DateTime('2020-01-01 11:22:33'), new DateTime('2040-01-01 22:33:44')]); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); @@ -99,7 +113,10 @@ test('dynamic min rule via control', function () { $input = $form->addDateTime('date') ->addRule($form::Min, null, $text); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/DateTimeControl.value.phpt b/tests/Controls/DateTimeControl.value.phpt index 8f0a4a378..a3b1d952a 100644 --- a/tests/Controls/DateTimeControl.value.phpt +++ b/tests/Controls/DateTimeControl.value.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Form, Validator}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/HiddenField.loadData.phpt b/tests/Controls/HiddenField.loadData.phpt index 6ffb5a5a8..885f60737 100644 --- a/tests/Controls/HiddenField.loadData.phpt +++ b/tests/Controls/HiddenField.loadData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/HiddenField.render.phpt b/tests/Controls/HiddenField.render.phpt index e91c828fe..22ea01ff6 100644 --- a/tests/Controls/HiddenField.render.phpt +++ b/tests/Controls/HiddenField.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/ImageButton.loadData.phpt b/tests/Controls/ImageButton.loadData.phpt index cb3539e44..04cef1b83 100644 --- a/tests/Controls/ImageButton.loadData.phpt +++ b/tests/Controls/ImageButton.loadData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/ImageButton.render.phpt b/tests/Controls/ImageButton.render.phpt index e387a5709..abede6c97 100644 --- a/tests/Controls/ImageButton.render.phpt +++ b/tests/Controls/ImageButton.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/MultiChoiceControl.loadData.phpt b/tests/Controls/MultiChoiceControl.loadData.phpt index be1c41a44..5af23413f 100644 --- a/tests/Controls/MultiChoiceControl.loadData.phpt +++ b/tests/Controls/MultiChoiceControl.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\{Form, Validator}; use Nette\Utils\DateTime; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/MultiSelectBox.loadData.phpt b/tests/Controls/MultiSelectBox.loadData.phpt index 0def53508..8058ba341 100644 --- a/tests/Controls/MultiSelectBox.loadData.phpt +++ b/tests/Controls/MultiSelectBox.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\{Form, Validator}; use Nette\Utils\DateTime; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/MultiSelectBox.render.phpt b/tests/Controls/MultiSelectBox.render.phpt index 543505479..7c4b6e4d9 100644 --- a/tests/Controls/MultiSelectBox.render.phpt +++ b/tests/Controls/MultiSelectBox.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -33,7 +32,10 @@ test('multi-select basic rendering', function () { Assert::same('', (string) $input->getLabel('Another label')); Assert::type(Html::class, $input->getControl()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -44,7 +46,10 @@ test('selected option rendering', function () { 0 => 'Second', ])->setValue(0); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -55,7 +60,10 @@ test('grouped options handling', function () { ['a' => 'First'], ])->setValue('a'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -69,7 +77,10 @@ test('translating options and groups', function () { Assert::same('', (string) $input->getLabel()); Assert::same('', (string) $input->getLabel('Another label')); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -83,7 +94,10 @@ test('HTML elements in options', function () { Assert::same('', (string) $input->getLabel()); Assert::same('', (string) $input->getLabel(Html::el('b', 'Another label'))); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -94,7 +108,10 @@ test('required multi-select validation', function () { 0 => 'Second', ])->setRequired('required'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -106,7 +123,10 @@ test('container naming in multi-select', function () { 0 => 'Second', ]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -115,9 +135,12 @@ test('disabled multi-select rendering', function () { $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ])->setDisabled(true); + ])->setDisabled(); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -128,7 +151,10 @@ test('disabling individual options', function () { 0 => 'Second', ])->setDisabled(['a']); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -153,5 +179,8 @@ test('dynamic option attributes', function () { $input->addOptionAttributes(['bar' => 'b', 'selected?' => 2]); $input->addOptionAttributes(['bar' => 'c']); $input->setOptionAttribute('foo:', [1 => 'a', 2 => 'b']); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/RadioList.loadData.phpt b/tests/Controls/RadioList.loadData.phpt index 19d047ae4..ca39905fb 100644 --- a/tests/Controls/RadioList.loadData.phpt +++ b/tests/Controls/RadioList.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\DateTime; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/RadioList.render.phpt b/tests/Controls/RadioList.render.phpt index 6574cd36a..3984a6e05 100644 --- a/tests/Controls/RadioList.render.phpt +++ b/tests/Controls/RadioList.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -36,7 +35,10 @@ test('radio list rendering basics', function () { Assert::same('', (string) $input->getLabelPart(0)); Assert::type(Html::class, $input->getControl()); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); Assert::type(Html::class, $input->getControlPart(0)); Assert::same('', (string) $input->getControlPart(0)); @@ -50,7 +52,10 @@ test('selected radio button', function () { 0 => 'Second', ])->setValue(0); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); @@ -66,7 +71,10 @@ test('translating radio options', function () { Assert::same('', (string) $input->getLabel('Another label')); Assert::same('', (string) $input->getLabelPart(0)); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); Assert::same('', (string) $input->getControlPart(0)); }); @@ -93,8 +101,14 @@ test('required radio list', function () { 0 => 'Second', ])->setRequired('required'); - Assert::same('
', (string) $input->getControl()); - Assert::same('', (string) $input->getControlPart(0)); + Assert::same( + '
', + (string) $input->getControl(), + ); + Assert::same( + '', + (string) $input->getControlPart(0), + ); }); @@ -106,7 +120,10 @@ test('container naming in radio', function () { 0 => 'Second', ]); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); @@ -127,9 +144,12 @@ test('disabled radio list', function () { $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ])->setDisabled(true); + ])->setDisabled(); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); @@ -140,7 +160,10 @@ test('disabled radio options', function () { 0 => 'Second', ])->setDisabled(['a']); - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); Assert::same('', (string) $input->getControlPart('a')); }); @@ -166,7 +189,10 @@ test('auto-generated IDs', function () { ]); $input->generateId = true; - Assert::same('
', (string) $input->getControl()); + Assert::same( + '
', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/SelectBox.isOk.phpt b/tests/Controls/SelectBox.isOk.phpt index a7383e680..45b6ce40c 100644 --- a/tests/Controls/SelectBox.isOk.phpt +++ b/tests/Controls/SelectBox.isOk.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Form, Validator}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -17,7 +16,7 @@ $select = $form->addSelect('foo', null, ['bar' => 'Bar']); Assert::false($select->isOk()); -$select->setDisabled(true); +$select->setDisabled(); Assert::true($select->isOk()); $select->setDisabled(false); diff --git a/tests/Controls/SelectBox.loadData.phpt b/tests/Controls/SelectBox.loadData.phpt index 0715d64b9..238d012ad 100644 --- a/tests/Controls/SelectBox.loadData.phpt +++ b/tests/Controls/SelectBox.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\DateTime; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/SelectBox.render.phpt b/tests/Controls/SelectBox.render.phpt index 24132db90..ef9f2ab30 100644 --- a/tests/Controls/SelectBox.render.phpt +++ b/tests/Controls/SelectBox.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -33,7 +32,10 @@ test('select box basic rendering', function () { Assert::same('', (string) $input->getLabel('Another label')); Assert::type(Html::class, $input->getControl()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -44,7 +46,10 @@ test('selected option rendering', function () { 0 => 'Second', ])->setValue(0); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -55,7 +60,10 @@ test('grouped options rendering', function () { ['a' => 'First'], ])->setValue('a'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -66,11 +74,17 @@ test('prompt option rendering', function () { 0 => 'Second', ])->setPrompt('prompt'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); $input->setValue(0); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -81,11 +95,17 @@ test('required select with prompt', function () { 0 => 'Second', ])->setPrompt('prompt')->setRequired(); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); $input->setValue(0); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -96,11 +116,17 @@ test('select with prompt and invalid selected value', function () { 0 => 'Second', ])->setPrompt('prompt')->checkDefaultValue(false); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); $input->setValue('does not exists'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -111,11 +137,17 @@ test('required select with prompt and invalid selected value', function () { 0 => 'Second', ])->setPrompt('prompt')->setRequired()->checkDefaultValue(false); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); $input->setValue('does not exists'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -125,11 +157,17 @@ test('empty value and prompt', function () { '' => 'First', ])->setPrompt('prompt'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); $input->setValue(''); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -143,7 +181,10 @@ test('translating prompt and options', function () { Assert::same('', (string) $input->getLabel()); Assert::same('', (string) $input->getLabel('Another label')); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -157,7 +198,10 @@ test('HTML in prompt and options', function () { Assert::same('', (string) $input->getLabel()); Assert::same('', (string) $input->getLabel(Html::el('b', 'Another label'))); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -168,7 +212,10 @@ test('required select box', function () { 0 => 'Second', ])->setRequired('required'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -180,7 +227,10 @@ test('container naming in select', function () { 0 => 'Second', ]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -189,9 +239,12 @@ test('disabled select rendering', function () { $input = $form->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ])->setDisabled(true); + ])->setDisabled(); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -202,7 +255,10 @@ test('disabled options rendering', function () { 0 => 'Second', ])->setDisabled(['a']); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -227,5 +283,8 @@ test('dynamic option attributes', function () { $input->addOptionAttributes(['bar' => 'b', 'selected?' => 2]); $input->addOptionAttributes(['bar' => 'c']); $input->setOptionAttribute('foo:', [1 => 'a', 2 => 'b']); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/TestBase.validators.phpt b/tests/Controls/TestBase.validators.phpt index f197d6a82..680af504d 100644 --- a/tests/Controls/TestBase.validators.phpt +++ b/tests/Controls/TestBase.validators.phpt @@ -9,7 +9,6 @@ use Nette\Forms\Validator; use Nette\Http\FileUpload; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -95,7 +94,7 @@ test('pattern matching validation', function () { test('object-based pattern validation', function () { $control = new TextInput; - $control->value = new class () { + $control->value = new class { public string $lorem = 'ipsum'; diff --git a/tests/Controls/TextArea.render.phpt b/tests/Controls/TextArea.render.phpt index 410de7f36..b7ee576f0 100644 --- a/tests/Controls/TextArea.render.phpt +++ b/tests/Controls/TextArea.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -64,7 +63,10 @@ test('length rule attributes', function () { $input = $form->addTextArea('text') ->addRule($form::Length, null, [10, 20]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -74,7 +76,10 @@ test('multiple max length rules', function () { ->addRule($form::MaxLength, null, 30) ->addRule($form::MaxLength, null, 10); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/TextBase.loadData.phpt b/tests/Controls/TextBase.loadData.phpt index 043de904b..c8051e709 100644 --- a/tests/Controls/TextBase.loadData.phpt +++ b/tests/Controls/TextBase.loadData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -130,7 +129,7 @@ test('conditional validation', function () { $form->allowCrossOrigin(); $input = $form->addText('number'); $input->addCondition($form::Filled) - ->addRule($form::Float); + ->addRule($form::Float); $input->validate(); Assert::same(10.5, $input->getValue()); @@ -142,8 +141,8 @@ test('negative rule handling', function () { $form = new Form; $form->allowCrossOrigin(); - $input = @$form->addText('number') - ->addRule(~$form::Float); // @ - negative rules are deprecated + $input = @$form->addText('number') // @ negative rules are deprecated + ->addRule(~$form::Float); $input->validate(); Assert::same(10.5, $input->getValue()); // side effect @@ -194,7 +193,7 @@ test('conditional filtering', function () { $form->allowCrossOrigin(); $input = $form->addText('text'); $input->addCondition($form::Filled) - ->addFilter('strrev'); + ->addFilter('strrev'); Assert::same('hello', $input->getValue()); $input->validate(); diff --git a/tests/Controls/TextInput.render.phpt b/tests/Controls/TextInput.render.phpt index 497483b66..374aae132 100644 --- a/tests/Controls/TextInput.render.phpt +++ b/tests/Controls/TextInput.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -46,7 +45,10 @@ test('translated attributes', function () { Assert::same('', (string) $input->getLabel()); Assert::same('', (string) $input->getLabel('Another label')); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -68,7 +70,10 @@ test('required rule with HTML', function () { Assert::same('', (string) $input->getLabel()); Assert::same('', (string) $input->getLabel(Html::el('b', 'Another label'))); Assert::type(Html::class, $input->getControl()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -89,14 +94,25 @@ test('input types and patterns', function () { foreach (['text', 'search', 'tel', 'url', 'email'] as $type) { $input->setHtmlType($type); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); } $input->setHtmlType('password'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); $input->setHtmlType('number'); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -104,9 +120,12 @@ test('nested validation rules', function () { $form = new Form; $input = $form->addText('text'); $input->addCondition($form::Filled) - ->addRule($form::Filled); + ->addRule($form::Filled); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -125,7 +144,10 @@ test('length rule precedence', function () { ->setMaxLength(30) ->addRule($form::Length, null, [10, 20]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -134,7 +156,10 @@ test('max length rule application', function () { $input = $form->addText('text', null, null, 30) ->addRule($form::MaxLength, null, 10); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -148,7 +173,10 @@ test('range and Min/Max rules', function () { ->addRule(Form::Max, 'Must be less than or equal to %d', 101) ->addRule(Form::Range, 'Must be in range from %d to %d', [$minInput, $maxInput]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -163,7 +191,10 @@ test('number input rules', function () { ->addRule(Form::Max, 'Must be less than or equal to %d', 101) ->addRule(Form::Range, 'Must be in range from %d to %d', [$minInput, $maxInput]); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -172,7 +203,10 @@ test('empty value attribute', function () { $input = $form->addText('text') ->setEmptyValue('empty '); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -192,7 +226,10 @@ test('nullable empty value', function () { ->setNullable(); Assert::null($input->getValue()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -232,7 +269,10 @@ test('integer input rendering', function () { Assert::null($input->getValue()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -242,7 +282,10 @@ test('float input rendering', function () { Assert::null($input->getValue()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -254,7 +297,10 @@ test('rule and filter interaction', function () { ->addRule(Form::Max, 'max', 10) ->addRule(Form::MaxLength, 'maxl', 10); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); @@ -266,5 +312,8 @@ test('email input rendering', function () { Assert::same('', (string) $input->getLabel()); Assert::type(Html::class, $input->getControl()); - Assert::same('', (string) $input->getControl()); + Assert::same( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Controls/TextInput.valueObjectValidation.phpt b/tests/Controls/TextInput.valueObjectValidation.phpt index 07252e0c5..de01b8876 100644 --- a/tests/Controls/TextInput.valueObjectValidation.phpt +++ b/tests/Controls/TextInput.valueObjectValidation.phpt @@ -7,18 +7,14 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; class ValueObject { - private string $value; - - - public function __construct(string $value) - { - $this->value = $value; + public function __construct( + private string $value, + ) { } diff --git a/tests/Controls/UploadControl.loadData.phpt b/tests/Controls/UploadControl.loadData.phpt index 4aacbabe6..7e33c271e 100644 --- a/tests/Controls/UploadControl.loadData.phpt +++ b/tests/Controls/UploadControl.loadData.phpt @@ -8,7 +8,6 @@ use Nette\Forms\{Form, Validator}; use Nette\Http\FileUpload; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Controls/UploadControl.render.phpt b/tests/Controls/UploadControl.render.phpt index 70db0d954..09678b5b5 100644 --- a/tests/Controls/UploadControl.render.phpt +++ b/tests/Controls/UploadControl.render.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -30,7 +29,10 @@ test('basic upload control rendering', function () { Assert::same('', (string) $input->getLabel('Another label')); Assert::type(Html::class, $input->getControl()); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); @@ -56,20 +58,32 @@ test('translated upload labels', function () { test('required upload attribute', function () { $form = new Form; $input = $form->addUpload('file')->setRequired('required'); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); test('MIME type validation attributes', function () { $form = new Form; $input = $form->addUpload('file1')->addRule(Form::MimeType, null, 'image/*'); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); $input = $form->addUpload('file2')->addRule(Form::MimeType, null, ['image/*', 'text/html']); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); $input = $form->addUpload('file3')->addRule(Form::Image); - Assert::match('', (string) $input->getControl()); + Assert::match( + '', + (string) $input->getControl(), + ); }); diff --git a/tests/Forms.DI/FormsExtension.phpt b/tests/Forms.DI/FormsExtension.phpt index 85a1e0066..04eeab045 100644 --- a/tests/Forms.DI/FormsExtension.phpt +++ b/tests/Forms.DI/FormsExtension.phpt @@ -9,7 +9,6 @@ use Nette\DI; use Nette\Forms\{Form, Validator}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms.Latte3/forms.phpt b/tests/Forms.Latte3/forms.phpt index c16ba8b72..cbd8ead49 100644 --- a/tests/Forms.Latte3/forms.phpt +++ b/tests/Forms.Latte3/forms.phpt @@ -33,7 +33,7 @@ $form->addText('username', 'Username:'); // must have just one textfield to gene $form['username']->getControlPrototype()->addClass('control-class'); $form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']); $form->addSelect('select', null, ['m' => 'male', 'f' => 'female']); -$form->addTextArea('area', null)->setValue('oneaddTextArea('area')->setValue('oneaddCheckbox('checkbox', 'Checkbox'); $form->addCheckboxList('checklist', 'CheckboxList:', ['m' => 'male', 'f' => 'female']); $form->addSubmit('send', 'Sign in'); diff --git a/tests/Forms/Blueprint.dataClass.phpt b/tests/Forms/Blueprint.dataClass.phpt index 7dab7c1a8..be5d5dba0 100644 --- a/tests/Forms/Blueprint.dataClass.phpt +++ b/tests/Forms/Blueprint.dataClass.phpt @@ -3,7 +3,6 @@ use Nette\Forms\{Blueprint, Form}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Blueprint.latte.phpt b/tests/Forms/Blueprint.latte.phpt index ec0c72a7e..fdd8145d7 100644 --- a/tests/Forms/Blueprint.latte.phpt +++ b/tests/Forms/Blueprint.latte.phpt @@ -4,7 +4,6 @@ use Nette\Forms\{Blueprint, Form}; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Container.extensionMethod.phpt b/tests/Forms/Container.extensionMethod.phpt index 0afb9ac30..a1904d103 100644 --- a/tests/Forms/Container.extensionMethod.phpt +++ b/tests/Forms/Container.extensionMethod.phpt @@ -3,7 +3,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Container.validate().phpt b/tests/Forms/Container.validate().phpt index dfb2ef1e5..1d4bd3daf 100644 --- a/tests/Forms/Container.validate().phpt +++ b/tests/Forms/Container.validate().phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Container, Form}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; $form = new Form; diff --git a/tests/Forms/Container.values.ArrayHash.phpt b/tests/Forms/Container.values.ArrayHash.phpt index 7ec314a5b..37126eda2 100644 --- a/tests/Forms/Container.values.ArrayHash.phpt +++ b/tests/Forms/Container.values.ArrayHash.phpt @@ -4,7 +4,6 @@ use Nette\Forms\Form; use Nette\Utils\ArrayHash; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Container.values.array.phpt b/tests/Forms/Container.values.array.phpt index 3cb54fad2..30ca93447 100644 --- a/tests/Forms/Container.values.array.phpt +++ b/tests/Forms/Container.values.array.phpt @@ -4,7 +4,6 @@ use Nette\Forms\Form; use Nette\Utils\ArrayHash; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Container.values.mapping-constructor.phpt b/tests/Forms/Container.values.mapping-constructor.phpt index 99190a3b6..f82008573 100644 --- a/tests/Forms/Container.values.mapping-constructor.phpt +++ b/tests/Forms/Container.values.mapping-constructor.phpt @@ -3,7 +3,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -67,7 +66,6 @@ test('mapping form values to constructor-injected objects', function () { title: 'new1', first: new FormFirstLevelConstruct( name: 'new2', - age: null, second: new FormSecondLevelConstruct( city: '', ), @@ -82,7 +80,6 @@ test('mapping form values to constructor-injected objects', function () { title: 'new1', first: new FormFirstLevelConstruct( name: 'new2', - age: null, second: new FormSecondLevelConstruct( city: '', ), diff --git a/tests/Forms/Container.values.mapping-enum.phpt b/tests/Forms/Container.values.mapping-enum.phpt index 34e7885cb..2520e926e 100644 --- a/tests/Forms/Container.values.mapping-enum.phpt +++ b/tests/Forms/Container.values.mapping-enum.phpt @@ -3,7 +3,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Container.values.mapping.phpt b/tests/Forms/Container.values.mapping.phpt index 28f671f3e..73d2b78ef 100644 --- a/tests/Forms/Container.values.mapping.phpt +++ b/tests/Forms/Container.values.mapping.phpt @@ -4,7 +4,6 @@ use Nette\Forms\Form; use Nette\Utils\{ArrayHash, Arrays}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/ControlGroup.phpt b/tests/Forms/ControlGroup.phpt index 1a350e4a7..212915b94 100644 --- a/tests/Forms/ControlGroup.phpt +++ b/tests/Forms/ControlGroup.phpt @@ -50,7 +50,10 @@ $container->addComponent(createContainer(), 'child'); $form->addComponent($container, 'parent'); Assert::equal(4, count($group->getControls())); -Assert::equal([$form['parent']['street'], $form['parent']['town'], $form['parent']['child']['street'], $form['parent']['child']['town']], $group->getControls()); +Assert::equal( + [$form['parent']['street'], $form['parent']['town'], $form['parent']['child']['street'], $form['parent']['child']['town']], + $group->getControls(), +); // container and controls diff --git a/tests/Forms/Forms.crossOrigin.phpt b/tests/Forms/Forms.crossOrigin.phpt index 5c0738e79..87238c8a4 100644 --- a/tests/Forms/Forms.crossOrigin.phpt +++ b/tests/Forms/Forms.crossOrigin.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.getHttpData.get.2.phpt b/tests/Forms/Forms.getHttpData.get.2.phpt index 705faa234..f75ca0c60 100644 --- a/tests/Forms/Forms.getHttpData.get.2.phpt +++ b/tests/Forms/Forms.getHttpData.get.2.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.getHttpData.get.phpt b/tests/Forms/Forms.getHttpData.get.phpt index ac7fa26f9..abfa8fb9c 100644 --- a/tests/Forms/Forms.getHttpData.get.phpt +++ b/tests/Forms/Forms.getHttpData.get.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.getHttpData.post.phpt b/tests/Forms/Forms.getHttpData.post.phpt index 588dcb149..f3d11089f 100644 --- a/tests/Forms/Forms.getHttpData.post.phpt +++ b/tests/Forms/Forms.getHttpData.post.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Form, Validator}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.idMask.phpt b/tests/Forms/Forms.idMask.phpt index 2369605e7..ce22a5d43 100644 --- a/tests/Forms/Forms.idMask.phpt +++ b/tests/Forms/Forms.idMask.phpt @@ -4,7 +4,6 @@ use Nette\Forms\Controls\TextInput; use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.isValid.phpt b/tests/Forms/Forms.isValid.phpt index 7623df1e3..702d31b87 100644 --- a/tests/Forms/Forms.isValid.phpt +++ b/tests/Forms/Forms.isValid.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.maxPostSize.phpt b/tests/Forms/Forms.maxPostSize.phpt index 67582c242..6242d5d68 100644 --- a/tests/Forms/Forms.maxPostSize.phpt +++ b/tests/Forms/Forms.maxPostSize.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.no.events.phpt b/tests/Forms/Forms.no.events.phpt index c3e9576fe..e425c6ee8 100644 --- a/tests/Forms/Forms.no.events.phpt +++ b/tests/Forms/Forms.no.events.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.omittedValue.phpt b/tests/Forms/Forms.omittedValue.phpt index 07d00c590..94e74eef6 100644 --- a/tests/Forms/Forms.omittedValue.phpt +++ b/tests/Forms/Forms.omittedValue.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Controls\TextInput; use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.onClick.phpt b/tests/Forms/Forms.onClick.phpt index 7fb445410..31ce43f13 100644 --- a/tests/Forms/Forms.onClick.phpt +++ b/tests/Forms/Forms.onClick.phpt @@ -4,7 +4,6 @@ use Nette\Forms\Controls\SubmitButton; use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.onRender.phpt b/tests/Forms/Forms.onRender.phpt index 747c4d1ae..31e0d745c 100644 --- a/tests/Forms/Forms.onRender.phpt +++ b/tests/Forms/Forms.onRender.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.onSuccess.phpt b/tests/Forms/Forms.onSuccess.phpt index 8fd385970..6bf832bd9 100644 --- a/tests/Forms/Forms.onSuccess.phpt +++ b/tests/Forms/Forms.onSuccess.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.renderer.1.phpt b/tests/Forms/Forms.renderer.1.phpt index 16033510b..1a4d97508 100644 --- a/tests/Forms/Forms.renderer.1.phpt +++ b/tests/Forms/Forms.renderer.1.phpt @@ -8,12 +8,24 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$_POST = ['name' => 'John Doe ', 'age' => '', 'email' => ' @ ', 'send' => 'on', 'street' => '', 'city' => '', 'country' => 'HU', 'password' => 'xxx', 'password2' => '', 'note' => '', 'submit1' => 'Send', 'userid' => '231']; +$_POST = [ + 'name' => 'John Doe ', + 'age' => '', + 'email' => ' @ ', + 'send' => 'on', + 'street' => '', + 'city' => '', + 'country' => 'HU', + 'password' => 'xxx', + 'password2' => '', + 'note' => '', + 'submit1' => 'Send', + 'userid' => '231', +]; $countries = [ @@ -38,7 +50,10 @@ $form->allowCrossOrigin(); $form->addGroup('Personal data') - ->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.') + ->setOption( + 'description', + 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.', + ) ->setOption('id', 'test-group-id-set-via-option'); $form->addText('name', 'Your name:') diff --git a/tests/Forms/Forms.renderer.2.phpt b/tests/Forms/Forms.renderer.2.phpt index a9c1bb2f2..c542f3b43 100644 --- a/tests/Forms/Forms.renderer.2.phpt +++ b/tests/Forms/Forms.renderer.2.phpt @@ -8,12 +8,23 @@ use Nette\Forms\Form; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$_POST = ['name' => 'John Doe ', 'age' => '9.9', 'email' => '@', 'street' => '', 'city' => 'Troubsko', 'country' => '0', 'password' => 'xx', 'password2' => 'xx', 'note' => '', 'submit1' => 'Send', 'userid' => '231']; +$_POST = [ + 'name' => 'John Doe ', + 'age' => '9.9', + 'email' => '@', + 'street' => '', + 'city' => 'Troubsko', + 'country' => '0', + 'password' => 'xx', + 'password2' => 'xx', + 'note' => '', + 'submit1' => 'Send', + 'userid' => '231', +]; $countries = [ diff --git a/tests/Forms/Forms.renderer.5.phpt b/tests/Forms/Forms.renderer.5.phpt index 90e8b5fc5..fdd912e73 100644 --- a/tests/Forms/Forms.renderer.5.phpt +++ b/tests/Forms/Forms.renderer.5.phpt @@ -41,7 +41,7 @@ $container = createContainer(); $container->addComponent(createContainer(), 'child'); $form->addComponent($container, 'parent'); -$form->setCurrentGroup(null); +$form->setCurrentGroup(); $form->addSubmit('submit', 'Order'); $form->fireEvents(); diff --git a/tests/Forms/Forms.renderer.translate.phpt b/tests/Forms/Forms.renderer.translate.phpt index 7a7243648..b780efc9a 100644 --- a/tests/Forms/Forms.renderer.translate.phpt +++ b/tests/Forms/Forms.renderer.translate.phpt @@ -34,7 +34,7 @@ $form->addText('username', 'Username') ->setOption('description', 'or email') ->setRequired('Please enter your username'); $form->addPassword('password', 'Password') - ->setRequired(true) + ->setRequired() ->addRule(Form::MinLength, 'Minimal length is %d chars', 8) ->addError('Weak password'); $form->addSubmit('submit', 'Send'); diff --git a/tests/Forms/Forms.submittedBy.phpt b/tests/Forms/Forms.submittedBy.phpt index deb666741..6ffc999fa 100644 --- a/tests/Forms/Forms.submittedBy.phpt +++ b/tests/Forms/Forms.submittedBy.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.toggle.phpt b/tests/Forms/Forms.toggle.phpt index 159bca174..9656c815d 100644 --- a/tests/Forms/Forms.toggle.phpt +++ b/tests/Forms/Forms.toggle.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Forms.userValidator.phpt b/tests/Forms/Forms.userValidator.phpt index 05459d446..a2470a2e8 100644 --- a/tests/Forms/Forms.userValidator.phpt +++ b/tests/Forms/Forms.userValidator.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -20,15 +19,15 @@ $datasets = [ function myValidator1($item, $arg) { - return $item->getValue() != $arg; + return $item->getValue() != $arg; // intentionally !=, a submitted value is a string } foreach ($datasets as $case) { $form = new Form; - $control = @$form->addText('value', 'Value:') + $control = @$form->addText('value', 'Value:') // @ negative rules are deprecated ->addRule('myValidator1', 'Value %d is not allowed!', 11) - ->addRule(~'myValidator1', 'Value %d is required!', 22); // @ - negative rules are deprecated + ->addRule(~'myValidator1', 'Value %d is required!', 22); $control->setValue($case[0])->validate(); Assert::same($case[1], $control->getErrors()); diff --git a/tests/Forms/Forms.validationScope.phpt b/tests/Forms/Forms.validationScope.phpt index 08d11240c..eb255e559 100644 --- a/tests/Forms/Forms.validationScope.phpt +++ b/tests/Forms/Forms.validationScope.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Container, Form}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Helpers.createInputList.phpt b/tests/Forms/Helpers.createInputList.phpt index b899a348d..efd1f06a7 100644 --- a/tests/Forms/Helpers.createInputList.phpt +++ b/tests/Forms/Helpers.createInputList.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Helpers; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -86,7 +85,7 @@ test('generating input lists with various configurations', function () { ['a' => 'First', 'b' => 'Second'], null, null, - Html::el(null), + Html::el(), ), ); }); diff --git a/tests/Forms/Helpers.createSelectBox.phpt b/tests/Forms/Helpers.createSelectBox.phpt index 2703f2310..a5adfaa22 100644 --- a/tests/Forms/Helpers.createSelectBox.phpt +++ b/tests/Forms/Helpers.createSelectBox.phpt @@ -8,7 +8,6 @@ use Nette\Forms\Helpers; use Nette\Utils\Html; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Helpers.exportRules.phpt b/tests/Forms/Helpers.exportRules.phpt index c69d3e7ae..4ba58dd39 100644 --- a/tests/Forms/Helpers.exportRules.phpt +++ b/tests/Forms/Helpers.exportRules.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Form, Helpers}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -38,7 +37,7 @@ test('exporting email validation rules', function () { test('combining required and email validation rules', function () { $form = new Form; $input = $form->addText('text'); - $input->setRequired(true); + $input->setRequired(); $input->addRule(Form::Email); Assert::same([ ['op' => ':filled', 'msg' => 'This field is required.'], @@ -64,7 +63,7 @@ test('conditional validation rule exports', function () { $input2 = $form->addText('text2'); $input2->setRequired(false); $input2->addConditionOn($input1, Form::Email) - ->setRequired(true) + ->setRequired() ->addRule($form::Email); $input2->addConditionOn($input1, Form::Integer) ->setRequired(false) diff --git a/tests/Forms/Helpers.extractHttpData.phpt b/tests/Forms/Helpers.extractHttpData.phpt index 192e202f0..aa8ffda9d 100644 --- a/tests/Forms/Helpers.extractHttpData.phpt +++ b/tests/Forms/Helpers.extractHttpData.phpt @@ -7,7 +7,6 @@ use Nette\Forms\{Form, Helpers}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -36,7 +35,10 @@ test('handling array data in HTTP extraction', function () { Assert::same(['1', '2'], Helpers::extractHttpData(['multi' => ['1', '2']], 'multi[]', Form::DataLine)); Assert::same(['1', '2'], Helpers::extractHttpData(['multi' => ['1', '2']], 'multi[]', Form::DataText)); Assert::same(['1', '2'], Helpers::extractHttpData(['multi' => ['x' => '1', 2 => '2']], 'multi[]', Form::DataText)); - Assert::same(['x' => '1', 2 => '2'], Helpers::extractHttpData(['multi' => ['x' => '1', 2 => '2']], 'multi[]', Form::DataKeys | Form::DataText)); + Assert::same( + ['x' => '1', 2 => '2'], + Helpers::extractHttpData(['multi' => ['x' => '1', 2 => '2']], 'multi[]', Form::DataKeys | Form::DataText), + ); Assert::same(['3', '4'], Helpers::extractHttpData([ 'container' => ['image' => ['3', '4']], diff --git a/tests/Forms/Helpers.generateHtmlName.phpt b/tests/Forms/Helpers.generateHtmlName.phpt index e1ca2eb6e..c9599169c 100644 --- a/tests/Forms/Helpers.generateHtmlName.phpt +++ b/tests/Forms/Helpers.generateHtmlName.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Helpers; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Rules.dynamic.phpt b/tests/Forms/Rules.dynamic.phpt index ac32d936e..6a63b572b 100644 --- a/tests/Forms/Rules.dynamic.phpt +++ b/tests/Forms/Rules.dynamic.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Rules.formatMessage.phpt b/tests/Forms/Rules.formatMessage.phpt index 44e1a2b93..717a7f38a 100644 --- a/tests/Forms/Rules.formatMessage.phpt +++ b/tests/Forms/Rules.formatMessage.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Rules.removeRule.phpt b/tests/Forms/Rules.removeRule.phpt index 58684e3e2..6e7842dcc 100644 --- a/tests/Forms/Rules.removeRule.phpt +++ b/tests/Forms/Rules.removeRule.phpt @@ -3,7 +3,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Rules.required.phpt b/tests/Forms/Rules.required.phpt index ae9b812d4..40f4b32db 100644 --- a/tests/Forms/Rules.required.phpt +++ b/tests/Forms/Rules.required.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -54,7 +53,7 @@ test('combining required with other validations', function () { Assert::same(Form::Required, $items[0]->validator); Assert::same(Form::Email, $items[1]->validator); - @$rules->addRule(~$form::Required); // @ - negative rules are deprecated + @$rules->addRule(~$form::Required); // @ negative rules are deprecated $items = iterator_to_array($rules); Assert::count(3, $items); Assert::same(Form::Blank, $items[0]->validator); @@ -111,6 +110,6 @@ test('negative required rule handling', function () { $input = $form->addText('text'); Assert::false($input->isRequired()); - Assert::same($input, @$input->addRule(~Form::Required)); // @ - negative rules are deprecated + Assert::same($input, @$input->addRule(~Form::Required)); // @ negative rules are deprecated Assert::false($input->isRequired()); }); diff --git a/tests/Forms/Rules.reset.phpt b/tests/Forms/Rules.reset.phpt index 8ad536ffb..65b0fa633 100644 --- a/tests/Forms/Rules.reset.phpt +++ b/tests/Forms/Rules.reset.phpt @@ -3,7 +3,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Rules.static.phpt b/tests/Forms/Rules.static.phpt index 9a7b82547..e9ccfc5ff 100644 --- a/tests/Forms/Rules.static.phpt +++ b/tests/Forms/Rules.static.phpt @@ -3,7 +3,6 @@ use Nette\Forms\{Form, Rules}; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; diff --git a/tests/Forms/Rules.valid.phpt b/tests/Forms/Rules.valid.phpt index cb8f0c40c..c6653bfd1 100644 --- a/tests/Forms/Rules.valid.phpt +++ b/tests/Forms/Rules.valid.phpt @@ -7,7 +7,6 @@ use Nette\Forms\Form; use Tester\Assert; - require __DIR__ . '/../bootstrap.php'; @@ -83,6 +82,6 @@ testException('exception on Valid in addCondition', function () { testException('exception on negative Valid rule', function () { $form = new Form; - @$form->addText('foo') - ->addRule(~Form::Valid); // @ - negative rules are deprecated + @$form->addText('foo') // @ negative rules are deprecated + ->addRule(~Form::Valid); }, Nette\InvalidArgumentException::class, 'You cannot use Form::Valid in the addRule method.'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a297aa39b..0b23b9598 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,7 +3,7 @@ // The Nette Tester command-line runner can be // invoked through the command: ../vendor/bin/tester . -if (@!include __DIR__ . '/../vendor/autoload.php') { +if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed echo 'Install Nette Tester using `composer install`'; exit(1); } diff --git a/tests/types/forms-types.php b/tests/types/forms-types.php index 1a5ad2ee9..7a3bf3aaa 100644 --- a/tests/types/forms-types.php +++ b/tests/types/forms-types.php @@ -26,7 +26,7 @@ function testFormContainerGetValues(Container $container): void function testFormContainerGetUntrustedValues(Container $container): void { - assertType('Nette\Utils\ArrayHash', $container->getUntrustedValues(null)); + assertType('Nette\Utils\ArrayHash', $container->getUntrustedValues()); assertType('array|array', $container->getUntrustedValues('array')); assertType(FormDto::class, $container->getUntrustedValues(FormDto::class)); } From cac7759e48c4f87f65118217b0fbc5c2e6f076b2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 14 Oct 2026 00:46:43 +0200 Subject: [PATCH 06/18] uses dresscode --- .gitattributes | 3 +- .github/workflows/coding-style.yml | 27 +++++++++--------- dresscode.neon | 45 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 dresscode.neon diff --git a/.gitattributes b/.gitattributes index e1bccc4bf..1c022ece0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,10 @@ .gitattributes export-ignore .github/ export-ignore .gitignore export-ignore -ncs.* export-ignore +dresscode.neon export-ignore phpstan*.neon export-ignore tests/ export-ignore +* text=auto *.php* diff=php *.sh text eol=lf diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml index a7b9fcc1a..9f9722039 100644 --- a/.github/workflows/coding-style.yml +++ b/.github/workflows/coding-style.yml @@ -3,38 +3,39 @@ name: Coding Style on: [push, pull_request] jobs: - nette_cc: - name: Nette Code Checker + dresscode: + name: DressCode runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.4 coverage: none - - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress - - run: php temp/code-checker/code-checker --strict-types --no-progress --ignore expected --ignore Forms.Latte2 + - run: composer install --no-progress --prefer-dist + - run: composer create-project dresscode/dresscode temp/dresscode ^1.1 --no-progress + - run: php temp/dresscode/bin/dresscode check - nette_cs: - name: Nette Coding Standard + nette_cc: + name: Nette Code Checker runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.4 coverage: none - - run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress - - run: php temp/coding-standard/ecs check src tests + - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress + - run: php temp/code-checker/code-checker --strict-types --no-progress --ignore expected --ignore Forms.Latte2 eslint: name: ESLint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - run: npm install - run: npm run lint diff --git a/dresscode.neon b/dresscode.neon new file mode 100644 index 000000000..61da722e7 --- /dev/null +++ b/dresscode.neon @@ -0,0 +1,45 @@ +use: + - nette + - modernizations + +typeAnalysis: phpstan + +paths: + - src + - tests + - examples + +excludePaths: + - tests/**/expected + +fileExtensions: + - php + - phpt + +imports: {grouping: {class: grouped}} + +overrides: + - + paths: [src] + nameResolution: certain + use: + - compilerOptimizations + - deprecations + - # the BC branch of the deprecated addProtection() and its message + paths: [src/Forms/Form.php, src/Forms/Validator.php] + upgrading: {declarations: {deprecatedClass: keep}} + - # Form::URL is established public API + paths: [src/Forms/Form.php] + naming: {constant: keep} + - # setValue($values) keeps its name, renaming it breaks named arguments + paths: [src/Forms/Controls/MultiChoiceControl.php] + classes: {overridingMethod: {parameterName: keep}} + - # setDisabled($value) keeps its name, renaming it breaks named arguments + paths: [src/Forms/Controls/ChoiceControl.php] + classes: {overridingMethod: {parameterName: keep}} + - # the parameter names come from the trait of nette/component-model + paths: [src/Forms/Container.php] + classes: {overridingMethod: {parameterName: keep}} + - # the alternative syntax suits PHP inside HTML + paths: [examples/manual-rendering.php] + braces: {alternativeSyntax: keep} From 2507f99aef963c46cee2e7e8d5e0184be455ae84 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 14 Oct 2026 00:47:08 +0200 Subject: [PATCH 07/18] added support for PHP 8.6 --- .github/workflows/tests.yml | 2 +- composer.json | 2 +- readme.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 465e22d7b..9ac74cefa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.1', '8.2', '8.3', '8.4', '8.5'] + php: ['8.1', '8.2', '8.3', '8.4', '8.5', '8.6'] fail-fast: false diff --git a/composer.json b/composer.json index bcf5c4810..2bcd0ffaa 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "8.1 - 8.5", + "php": "8.1 - 8.6", "nette/component-model": "^3.1", "nette/http": "^3.3", "nette/utils": "^4.0.4" diff --git a/readme.md b/readme.md index ebcd0fd44..9c61b0ffb 100644 --- a/readme.md +++ b/readme.md @@ -44,7 +44,7 @@ The recommended way to install is via Composer: composer require nette/forms ``` -It requires PHP version 8.1 and supports PHP up to 8.5. +It requires PHP version 8.1 and supports PHP up to 8.6. Client-side support can be installed with npm or yarn: From 0e15c9a7e74b1f9015b2d4ba0ff6bace05fe4583 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 29 May 2026 08:59:16 +0200 Subject: [PATCH 08/18] improved phpDoc added @property $name to suppress deprecation from nette/component-model --- src/Forms/Container.php | 1 + src/Forms/Controls/BaseControl.php | 12 ++++-- src/Forms/Controls/TextBase.php | 2 +- src/Forms/Controls/TextInput.php | 2 +- src/Forms/Controls/UploadControl.php | 2 +- src/Forms/Rule.php | 2 +- src/Forms/Rules.php | 8 ++-- tests/types/forms-types.php | 60 ++++++++++++++++++++++++++++ 8 files changed, 77 insertions(+), 12 deletions(-) diff --git a/src/Forms/Container.php b/src/Forms/Container.php index a57706cb1..f3b7ad2e5 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -16,6 +16,7 @@ /** * Container for form controls. * + * @property-read string $name * @property ArrayHash $values * @property-read \Iterator $controls * @property-read ?Form $form diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index a97ade484..541f398fd 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -17,6 +17,7 @@ /** * Base implementation for form controls with HTML rendering, validation, translation, and option support. * + * @property-read string $name * @property-read Form $form * @property-read string $htmlName * @property string|bool|null $htmlId @@ -390,7 +391,7 @@ public function translate(mixed $value, mixed ...$parameters): mixed /** * Adds a validation rule. - * @param (callable(Control): bool)|string $validator + * @param (callable(Control, mixed): bool)|string $validator * @return static */ public function addRule( @@ -405,7 +406,7 @@ public function addRule( /** * Adds a validation condition and returns a new branch. - * @param (callable(Control): bool)|string|bool $validator + * @param (callable(Control, mixed): bool)|string|bool $validator */ public function addCondition($validator, mixed $value = null): Rules { @@ -415,7 +416,7 @@ public function addCondition($validator, mixed $value = null): Rules /** * Adds a validation condition based on another control and returns a new branch. - * @param (callable(Control): bool)|string $validator + * @param (callable(Control, mixed): bool)|string $validator */ public function addConditionOn(Control $control, $validator, mixed $value = null): Rules { @@ -557,7 +558,10 @@ public function getOptions(): array /********************* extension methods ****************d*g**/ - /** @param mixed[] $args */ + /** + * @param mixed[] $args + * @return mixed + */ public function __call(string $name, array $args) { $class = static::class; diff --git a/src/Forms/Controls/TextBase.php b/src/Forms/Controls/TextBase.php index c13cebb96..16314c0c1 100644 --- a/src/Forms/Controls/TextBase.php +++ b/src/Forms/Controls/TextBase.php @@ -127,7 +127,7 @@ protected function getRenderedValue(): ?string /** - * @param (callable(Nette\Forms\Control): bool)|string $validator + * @param (callable(Nette\Forms\Control, mixed): bool)|string $validator * @return static */ public function addRule( diff --git a/src/Forms/Controls/TextInput.php b/src/Forms/Controls/TextInput.php index 3dfd0a171..914a15699 100644 --- a/src/Forms/Controls/TextInput.php +++ b/src/Forms/Controls/TextInput.php @@ -61,7 +61,7 @@ public function getControl(): Nette\Utils\Html /** - * @param (callable(Nette\Forms\Control): bool)|string $validator + * @param (callable(Nette\Forms\Control, mixed): bool)|string $validator * @return static */ public function addRule( diff --git a/src/Forms/Controls/UploadControl.php b/src/Forms/Controls/UploadControl.php index d7728e22e..070b0dd2a 100644 --- a/src/Forms/Controls/UploadControl.php +++ b/src/Forms/Controls/UploadControl.php @@ -125,7 +125,7 @@ public function isOk(): bool /** - * @param (callable(Nette\Forms\Control): bool)|string $validator + * @param (callable(Nette\Forms\Control, mixed): bool)|string $validator * @return static */ public function addRule( diff --git a/src/Forms/Rule.php b/src/Forms/Rule.php index 9a0b0563d..7c5cf5565 100644 --- a/src/Forms/Rule.php +++ b/src/Forms/Rule.php @@ -19,7 +19,7 @@ final class Rule { public Control $control; - /** @var (callable(Control): bool)|string */ + /** @var (callable(Control, mixed): bool)|string */ public mixed $validator; public mixed $arg = null; public bool $isNegative = false; diff --git a/src/Forms/Rules.php b/src/Forms/Rules.php index 016fd84cd..794dffe58 100644 --- a/src/Forms/Rules.php +++ b/src/Forms/Rules.php @@ -65,7 +65,7 @@ public function isRequired(): bool /** * Adds a validation rule for the current control. - * @param (callable(Control): bool)|string $validator + * @param (callable(Control, mixed): bool)|string $validator */ public function addRule( callable|string $validator, @@ -95,7 +95,7 @@ public function addRule( /** * Removes a validation rule for the current control. - * @param (callable(Control): bool)|string $validator + * @param (callable(Control, mixed): bool)|string $validator */ public function removeRule(callable|string $validator): static { @@ -115,7 +115,7 @@ public function removeRule(callable|string $validator): static /** * Adds a validation condition and returns new branch. - * @param (callable(Control): bool)|string|bool $validator + * @param (callable(Control, mixed): bool)|string|bool $validator */ public function addCondition(callable|string|bool $validator, mixed $arg = null): static { @@ -132,7 +132,7 @@ public function addCondition(callable|string|bool $validator, mixed $arg = null) /** * Adds a validation condition on a specified control and returns new branch. - * @param (callable(Control): bool)|string $validator + * @param (callable(Control, mixed): bool)|string $validator */ public function addConditionOn(Control $control, callable|string $validator, mixed $arg = null): static { diff --git a/tests/types/forms-types.php b/tests/types/forms-types.php index 7a3bf3aaa..09489129b 100644 --- a/tests/types/forms-types.php +++ b/tests/types/forms-types.php @@ -49,3 +49,63 @@ function testFormEvents(Form $form): void assertType(Form::class, $form); }; } + + +// Issue #350: addRule() must accept validators with a second $arg parameter +function testAddRuleValidatorOneParam(Form $form): void +{ + $form->addText('field') + ->addRule(fn(Nette\Forms\Control $input): bool => (bool) $input->getValue()); +} + + +function testAddRuleValidatorTwoParams(Form $form): void +{ + $form->addInteger('num') + ->addRule( + fn(Nette\Forms\Control $input, mixed $arg): bool => $input->getValue() > $arg, + 'Must be greater than %d', + 0, + ); +} + + +function testAddRuleStaticCallableWithArg(Form $form): void +{ + $form->addInteger('num') + ->addRule( + [CustomValidators::class, 'validateDivisibility'], + 'Must be divisible by %d', + 8, + ); +} + + +// addCondition() with one-parameter handler +function testAddConditionOneParam(Form $form): void +{ + $form->addText('field') + ->addCondition(fn(Nette\Forms\Control $input): bool => (bool) $input->getValue()) + ->setRequired(); +} + + +// addCondition() with two-parameter handler +function testAddConditionTwoParams(Form $form): void +{ + $form->addInteger('num') + ->addCondition( + fn(Nette\Forms\Control $input, mixed $arg): bool => $input->getValue() > $arg, + 0, + ) + ->setRequired(); +} + + +class CustomValidators +{ + public static function validateDivisibility(Nette\Forms\Control $input, mixed $arg): bool + { + return $input->getValue() % $arg === 0; + } +} From 3e453e72532a74dbba87c95c5df5d3cf066ce21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20L=C3=ADbal?= Date: Mon, 29 Jun 2026 20:52:50 +0200 Subject: [PATCH 09/18] improved phpDoc types --- src/Forms/Form.php | 2 +- tests/types/forms-types.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Forms/Form.php b/src/Forms/Form.php index ff8d61d23..f392c816a 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -437,7 +437,7 @@ public function setSubmittedBy(?SubmitterControl $by): static /** * Returns raw submitted HTTP data for a control, or all form data when called without arguments. - * @return string|string[]|Nette\Http\FileUpload|null + * @return ($htmlName is null ? mixed[] : string|string[]|Nette\Http\FileUpload|Nette\Http\FileUpload[]|null) */ public function getHttpData(?int $type = null, ?string $htmlName = null): string|array|Nette\Http\FileUpload|null { diff --git a/tests/types/forms-types.php b/tests/types/forms-types.php index 09489129b..71f83c042 100644 --- a/tests/types/forms-types.php +++ b/tests/types/forms-types.php @@ -109,3 +109,11 @@ public static function validateDivisibility(Nette\Forms\Control $input, mixed $a return $input->getValue() % $arg === 0; } } + + +// Issue #351: getHttpData() without arguments returns the whole nested data, not string[] +function testFormGetHttpData(Form $form): void +{ + assertType('array', $form->getHttpData()); + assertType('array|Nette\Http\FileUpload|string|null', $form->getHttpData(Form::DataLine, 'name')); +} From 95f74311f291e1e09eeb8e2eda3384cbcd47011c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 28 May 2026 01:48:03 +0200 Subject: [PATCH 10/18] phpstan fixes --- phpstan.neon | 16 ++++++++++------ src/Forms/Controls/CsrfProtection.php | 4 +--- src/Forms/Form.php | 8 ++++++-- src/Forms/Rendering/DefaultFormRenderer.php | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 7d9a63e92..9307b6370 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -37,6 +37,15 @@ parameters: path: src/Forms/Controls/SubmitButton.php count: 1 + - # isSameSite() exists on the Nette\Http\Request implementation but the IRequest + # interface does not declare it (it is deprecated there in favour of isFrom()). + # We deliberately keep calling isSameSite() for compatibility with older nette/http + # ^3.3 releases where isFrom() does not yet exist. + identifier: method.notFound + message: '#^Call to an undefined method Nette\\Http\\IRequest::isSameSite\(\)\.$#' + path: src/Forms/Form.php + count: 1 + - # Nette\Forms\Control interface is intentionally minimal and missing common methods # (getControl, getLabel, getForm, getOption, setOption, getHtmlName, getName, getParent, # lookupPath, hasErrors, isRequired, isFilled, isDisabled, addError). In practice all @@ -130,6 +139,7 @@ parameters: # for better type safety - the contravariance is by design. identifier: method.childParameterType message: '#^Parameter \#1 \$value \([^)]+\) of method Nette\\Forms\\Controls\\\w+::setValue\(\) should be contravariant with parameter \$value \(mixed\) of method Nette\\Forms\\(Control|Controls\\BaseControl)::setValue\(\)$#' + path: src/Forms/Controls - # Rules::getCallback() returns callable-array [class, method] without value type. message: '#^Method Nette\\Forms\\Rules::getCallback\(\) return type has no value type specified in iterable type array\.$#' @@ -179,9 +189,3 @@ parameters: identifier: function.alreadyNarrowedType count: 1 path: src/Forms/Controls/ColorPicker.php - - - - message: '#^Strict comparison using \=\=\= between '''' and '''' will always evaluate to true\.$#' - identifier: identical.alwaysTrue - count: 1 - path: src/Forms/Helpers.php diff --git a/src/Forms/Controls/CsrfProtection.php b/src/Forms/Controls/CsrfProtection.php index 768d16b23..1e97344ea 100644 --- a/src/Forms/Controls/CsrfProtection.php +++ b/src/Forms/Controls/CsrfProtection.php @@ -34,9 +34,7 @@ public function __construct(string|Stringable|null $errorMessage = null) $this->monitor(Presenter::class, function (Presenter $presenter): void { if (!$this->session) { - $session = $presenter->getSession(); - assert($session instanceof Nette\Http\Session); - $this->session = $session; + $this->session = $presenter->getSession(); $this->session->start(); } }); diff --git a/src/Forms/Form.php b/src/Forms/Form.php index f392c816a..9380ffb19 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -306,8 +306,12 @@ public function allowCrossOrigin(): void public function addProtection(?string $errorMessage = null): Controls\CsrfProtection { $control = new Controls\CsrfProtection($errorMessage); - $children = $this->getComponents(); - $first = $children ? (string) array_key_first($children) : null; + $first = null; + foreach ($this->getComponents() as $name => $component) { + $first = (string) $name; + break; + } + $this->addComponent($control, self::ProtectorId, $first); return $control; } diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index d2a05d7e2..3fa6d502b 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -489,6 +489,7 @@ public function renderControl(Nette\Forms\Control $control): Html if ($nextTo = $control->getOption('nextTo')) { $control = $control->getForm()->getComponent($nextTo); + assert($control instanceof Nette\Forms\Control); $body->class($this->getValue('control .multi'), true); goto renderControl; } From 9bc8f967380b4c85ac906e154e228ba69ab5045e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 16 Jun 2026 17:30:58 +0200 Subject: [PATCH 11/18] removed return type from Container::__call() [Closes nette/utils#338] The fatal error appears only when a subclass extends Form/Container AND re-applies the SmartObject trait, e.g.: --- src/Forms/Container.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Forms/Container.php b/src/Forms/Container.php index f3b7ad2e5..5c0eef4c0 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -605,8 +605,11 @@ public function addContainer(string|int $name): self /********************* extension methods ****************d*g**/ - /** @param mixed[] $args */ - public function __call(string $name, array $args): mixed + /** + * @param mixed[] $args + * @return mixed + */ + public function __call(string $name, array $args) { if (isset(self::$extMethods[$name])) { return (self::$extMethods[$name])($this, ...$args); From 255c820f6fbad279347c8bf207fece2ce7cc1f70 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 28 Jun 2026 12:50:36 +0200 Subject: [PATCH 12/18] Helpers::tryEnumConversion() no longer throws on incompatible input When mapping a text/hidden control onto a backed-enum property, the raw submitted value was passed straight to BackedEnum::from(). Under strict_types that rejects any mismatch: an int-backed enum given a non-numeric string (e.g. an empty field) raised TypeError, an out-of-range value raised ValueError. The method is now total: it converts only when a matching case exists - coercing numeric strings to the int backing type so int-backed enums map from form input at all - and returns the value unchanged otherwise. This only makes the helper itself safe; it does not add enum-membership validation. A required enum property fed an invalid value still fails later at the typed assignment in the target object's constructor, which is generic typed-mapping behaviour, not specific to enums. --- src/Forms/Helpers.php | 18 +++-- .../Forms/Container.values.mapping-enum.phpt | 71 ++++++++++++++++++- 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index b4fcf04bf..5cd991c47 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -334,15 +334,21 @@ public static function tryEnumConversion( \ReflectionParameter|\ReflectionProperty|null $reflection, ): mixed { - if ($value !== null - && $reflection - && ($type = Nette\Utils\Type::fromReflection($reflection)?->getSingleName()) - && is_a($type, \BackedEnum::class, allow_string: true) + if ($value === null + || !$reflection + || !($type = Nette\Utils\Type::fromReflection($reflection)?->getSingleName()) + || !is_a($type, \BackedEnum::class, allow_string: true) ) { - return $type::from($value); + return $value; + } + + // form values arrive as strings, so int-backed enums need explicit conversion + if ((new \ReflectionEnum($type))->getBackingType()?->getName() === 'int') { + $int = filter_var($value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); + return $int === null ? $value : ($type::tryFrom($int) ?? $value); } - return $value; + return is_string($value) ? ($type::tryFrom($value) ?? $value) : $value; } diff --git a/tests/Forms/Container.values.mapping-enum.phpt b/tests/Forms/Container.values.mapping-enum.phpt index 2520e926e..7b7d0d730 100644 --- a/tests/Forms/Container.values.mapping-enum.phpt +++ b/tests/Forms/Container.values.mapping-enum.phpt @@ -1,6 +1,6 @@ getValues(FormWithEnum::class)); }); + + +test('mapping a numeric string to an int-backed enum', function () { + $form = new Form; + $form->addText('value'); + $form->setValues(['value' => '1']); + + Assert::equal(new FormWithIntEnum(IntEnum::One), $form->getValues(FormWithIntEnum::class)); +}); + + +test('mapping a numeric string to a string-backed enum', function () { + $form = new Form; + $form->addText('value'); + $form->setValues(['value' => '1']); + + Assert::equal(new FormWithStringIntEnum(StringIntEnum::One), $form->getValues(FormWithStringIntEnum::class)); +}); + + +test('incompatible values are left unchanged instead of raising TypeError/ValueError', function () { + $intRef = new ReflectionProperty(FormWithIntEnum::class, 'value'); + $strRef = (new ReflectionClass(FormWithEnum::class))->getConstructor()->getParameters()[0]; + $strIntRef = new ReflectionProperty(FormWithStringIntEnum::class, 'value'); + + // int-backed enum + Assert::same(IntEnum::One, Helpers::tryEnumConversion('1', $intRef)); + Assert::same('abc', Helpers::tryEnumConversion('abc', $intRef)); // was TypeError + Assert::same('', Helpers::tryEnumConversion('', $intRef)); // empty field, was TypeError + Assert::same('9', Helpers::tryEnumConversion('9', $intRef)); // valid type, unknown case, was ValueError + + // string-backed enum + Assert::same(TestEnum::Case1, Helpers::tryEnumConversion('case 1', $strRef)); + Assert::same('zzz', Helpers::tryEnumConversion('zzz', $strRef)); // unknown case, was ValueError + + // string-backed enum with numeric values (submitted as string) + Assert::same(StringIntEnum::One, Helpers::tryEnumConversion('1', $strIntRef)); + Assert::same('9', Helpers::tryEnumConversion('9', $strIntRef)); // unknown case, was ValueError + + Assert::null(Helpers::tryEnumConversion(null, $intRef)); +}); From 5e243d91daaf6d4fa2a8bf539fcac63f3b4ca25e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 20 Oct 2026 14:22:48 +0200 Subject: [PATCH 13/18] ColorPicker: rejects values longer than #rrggbb The unanchored regex accepted values like #336699ff or 1234567. --- src/Forms/Controls/ColorPicker.php | 2 +- tests/Controls/ColorPicker.loadData.phpt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Forms/Controls/ColorPicker.php b/src/Forms/Controls/ColorPicker.php index 50b13ef99..9da6d53a9 100644 --- a/src/Forms/Controls/ColorPicker.php +++ b/src/Forms/Controls/ColorPicker.php @@ -31,7 +31,7 @@ public function setValue($value): static { if ($value === null) { $this->value = '#000000'; - } elseif (is_string($value) && preg_match('~#?[0-9a-f]{6}~Ai', $value)) { + } elseif (is_string($value) && preg_match('~#?[0-9a-f]{6}\z~Ai', $value)) { $this->value = '#' . strtolower(ltrim($value, '#')); } else { throw new Nette\InvalidArgumentException('Color must have #rrggbb format.'); diff --git a/tests/Controls/ColorPicker.loadData.phpt b/tests/Controls/ColorPicker.loadData.phpt index 9b7154c20..ab715e298 100644 --- a/tests/Controls/ColorPicker.loadData.phpt +++ b/tests/Controls/ColorPicker.loadData.phpt @@ -52,3 +52,20 @@ test('valid color value handling', function () { Assert::same('#1020aa', $input->getValue()); Assert::true($input->isFilled()); }); + + +test('too long values are rejected, not truncated', function () { + $_POST = ['color' => '#336699ff']; + + $form = new Form; + $form->allowCrossOrigin(); + $input = $form->addColor('color'); + + Assert::same('#000000', $input->getValue()); + + Assert::exception( + fn() => $input->setValue('1234567'), + Nette\InvalidArgumentException::class, + 'Color must have #rrggbb format.', + ); +}); From 4dcce7da611fee86e1a499ce4062869ae96d8d80 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 18:02:32 +0100 Subject: [PATCH 14/18] GET form: query parameter without a value in action no longer throws [Closes #348] --- src/Bridges/FormsLatte/Runtime.php | 2 +- src/Forms/Rendering/DefaultFormRenderer.php | 2 +- tests/Forms.Latte3/Runtime.get.phpt | 4 ++-- tests/Forms/Forms.renderer.4.phpt | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Bridges/FormsLatte/Runtime.php b/src/Bridges/FormsLatte/Runtime.php index 16561a393..d53725479 100644 --- a/src/Bridges/FormsLatte/Runtime.php +++ b/src/Bridges/FormsLatte/Runtime.php @@ -68,7 +68,7 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string $name = urldecode($parts[0]); $prefix = explode('[', $name, 2)[0]; if (!isset($form[$prefix])) { - $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]); + $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1] ?? '')]); } } } diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index 3fa6d502b..009fed4f3 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -174,7 +174,7 @@ public function renderBegin(): string $name = urldecode($parts[0]); $prefix = explode('[', $name, 2)[0]; if (!isset($this->form[$prefix])) { - $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]); + $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1] ?? '')]); } } diff --git a/tests/Forms.Latte3/Runtime.get.phpt b/tests/Forms.Latte3/Runtime.get.phpt index 77f5a2f10..8dd856f9d 100644 --- a/tests/Forms.Latte3/Runtime.get.phpt +++ b/tests/Forms.Latte3/Runtime.get.phpt @@ -11,7 +11,7 @@ $form = new Form; $form->setMethod('GET'); $form->addText('arg1'); $form->addText('arg2'); -$form->setAction('http://example.com/?do=foo-submit&arg0=1&arg1=1&arg2[x]=1#toc'); +$form->setAction('http://example.com/?do=foo-submit&arg0=1&flag&arg1=1&arg2[x]=1#toc'); Assert::same( '', @@ -19,6 +19,6 @@ Assert::same( ); Assert::match( - '', + '', Runtime::renderFormEnd($form), ); diff --git a/tests/Forms/Forms.renderer.4.phpt b/tests/Forms/Forms.renderer.4.phpt index b86ab47ac..38315b844 100644 --- a/tests/Forms/Forms.renderer.4.phpt +++ b/tests/Forms/Forms.renderer.4.phpt @@ -11,7 +11,7 @@ require __DIR__ . '/../bootstrap.php'; $form = new Nette\Forms\Form; $form->setMethod('GET'); -$form->setAction('link?a=b&c[]=d&list[0]=1'); +$form->setAction('link?a=b&c[]=d&flag&list[0]=1'); $form->addCheckboxList('list') ->setItems(['First', 'Second']); $form->addHidden('userid'); @@ -20,7 +20,7 @@ $form->addSubmit('submit', 'Send'); $form->fireEvents(); Assert::match('
- + @@ -39,4 +39,4 @@ Assert::match('', $form->__toString(true)); -Assert::same('link?a=b&c[]=d&list[0]=1', $form->getAction()); +Assert::same('link?a=b&c[]=d&flag&list[0]=1', $form->getAction()); From fdafb968957269943bef2a997e5ae033fe603d98 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 18:04:36 +0100 Subject: [PATCH 15/18] Stringable messages and translations no longer throw TypeError [Closes #349] A rule message given as Stringable, and a translator returning Stringable, crashed in validation messages, select optgroups and the empty value. Reported in #349 and #312. --- src/Forms/Controls/MultiSelectBox.php | 2 +- src/Forms/Controls/SelectBox.php | 2 +- src/Forms/Controls/TextBase.php | 4 +- src/Forms/Validator.php | 2 +- tests/Forms/Forms.stringable.phpt | 64 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 tests/Forms/Forms.stringable.phpt diff --git a/src/Forms/Controls/MultiSelectBox.php b/src/Forms/Controls/MultiSelectBox.php index 82eefdc70..80f9b7ba0 100644 --- a/src/Forms/Controls/MultiSelectBox.php +++ b/src/Forms/Controls/MultiSelectBox.php @@ -63,7 +63,7 @@ public function getControl(): Nette\Utils\Html { $items = []; foreach ($this->options as $key => $value) { - $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value); + $items[is_array($value) ? (string) $this->translate($key) : $key] = $this->translate($value); } return Nette\Forms\Helpers::createSelectBox( diff --git a/src/Forms/Controls/SelectBox.php b/src/Forms/Controls/SelectBox.php index b8a2eb67d..e4539db83 100644 --- a/src/Forms/Controls/SelectBox.php +++ b/src/Forms/Controls/SelectBox.php @@ -95,7 +95,7 @@ public function getControl(): Nette\Utils\Html { $items = []; foreach ($this->options as $key => $value) { - $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value); + $items[is_array($value) ? (string) $this->translate($key) : $key] = $this->translate($value); } $attrs = $this->optionAttributes; diff --git a/src/Forms/Controls/TextBase.php b/src/Forms/Controls/TextBase.php index 16314c0c1..103f37fa6 100644 --- a/src/Forms/Controls/TextBase.php +++ b/src/Forms/Controls/TextBase.php @@ -51,7 +51,7 @@ public function setValue(mixed $value) */ public function getValue(): mixed { - $value = $this->value === Strings::trim($this->translate($this->emptyValue)) + $value = $this->value === Strings::trim((string) $this->translate($this->emptyValue)) ? '' : $this->value; return $this->nullable && $value === '' ? null : $value; @@ -107,7 +107,7 @@ public function getControl(): Nette\Utils\Html { $el = parent::getControl(); if ($this->emptyValue !== '') { - $el->attrs['data-nette-empty-value'] = Strings::trim($this->translate($this->emptyValue)); + $el->attrs['data-nette-empty-value'] = Strings::trim((string) $this->translate($this->emptyValue)); } if (isset($el->placeholder)) { diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index d6de0ee71..42214c67a 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -104,7 +104,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string return $arg; } } - }, $message); + }, (string) $message); return $message; } diff --git a/tests/Forms/Forms.stringable.phpt b/tests/Forms/Forms.stringable.phpt new file mode 100644 index 000000000..1fabd0453 --- /dev/null +++ b/tests/Forms/Forms.stringable.phpt @@ -0,0 +1,64 @@ +text; + } +} + + +test('rule message as Stringable', function () { + $form = new Form; + $form->addText('mail', 'Mail:') + ->addRule(Form::Email, new Message('%value of %label is not an e-mail')) + ->setDefaultValue('xx'); + + $form->validate(); + Assert::same(['xx of Mail is not an e-mail'], $form->getErrors()); + Assert::contains('"msg":"%value of Mail is not an e-mail"', (string) $form['mail']->getControl()); +}); + + +test('translator returning Stringable', function () { + $form = new Form; + $form->setTranslator(new class implements Translator { + public function translate(string|Stringable $message, mixed ...$parameters): Stringable + { + return new Message("[$message]"); + } + }); + + $form->addText('mail', 'Mail') + ->setEmptyValue('none') + ->addRule(Form::Email, '%value is invalid') + ->setDefaultValue('xx'); + $form->addSelect('select', null, ['group' => ['a' => 'item']]) + ->setDefaultValue('a'); + $form->addMultiSelect('multi', null, ['group' => ['a' => 'item']]); + + $form->validate(); + Assert::same(['[xx is invalid]'], $form->getErrors()); + Assert::same('xx', $form['mail']->getValue()); + Assert::contains('data-nette-empty-value="[none]"', (string) $form['mail']->getControl()); + Assert::contains('', (string) $form['select']->getControl()); + Assert::contains('', (string) $form['multi']->getControl()); +}); From 84ebecb21270716beb90ec0a85f06aa715b4a44d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 18:06:31 +0100 Subject: [PATCH 16/18] Validator: rules Filled, Blank and Valid accept any Control implementation [Closes #346] --- src/Forms/Validator.php | 6 +- tests/Forms/Rules.customControl.phpt | 102 +++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 tests/Forms/Rules.customControl.phpt diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index 42214c67a..bfe1741e5 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -160,7 +160,7 @@ public static function validateStatic(Control $control, bool $arg): bool /** * Checks whether the control is filled. */ - public static function validateFilled(Controls\BaseControl $control): bool + public static function validateFilled(Control $control): bool { return $control->isFilled(); } @@ -169,7 +169,7 @@ public static function validateFilled(Controls\BaseControl $control): bool /** * Checks whether the control is not filled. */ - public static function validateBlank(Controls\BaseControl $control): bool + public static function validateBlank(Control $control): bool { return !$control->isFilled(); } @@ -178,7 +178,7 @@ public static function validateBlank(Controls\BaseControl $control): bool /** * Checks whether the control passes all its validation rules (used in conditions). */ - public static function validateValid(Controls\BaseControl $control): bool + public static function validateValid(Control $control): bool { return $control->getRules()->validate(); } diff --git a/tests/Forms/Rules.customControl.phpt b/tests/Forms/Rules.customControl.phpt new file mode 100644 index 000000000..e7cee99b7 --- /dev/null +++ b/tests/Forms/Rules.customControl.phpt @@ -0,0 +1,102 @@ +value = $value; + return $this; + } + + + public function getValue(): mixed + { + return $this->value; + } + + + public function isFilled(): bool + { + return $this->value !== null && $this->value !== ''; + } + + + public function getRules(): Rules + { + return $this->rules ??= new Rules($this); + } + + + public function getForm(bool $throw = true): ?Form + { + return $this->lookup(Form::class, $throw); + } + + + public function validate(): void + { + $this->getRules()->validate(); + } + + + public function addError(string|Stringable $message, bool $translate = true): void + { + $this->errors[] = $message; + } + + + public function getErrors(): array + { + return $this->errors; + } + + + public function isOmitted(): bool + { + return false; + } +} + + +ob_start(); + +test('required', function () { + $form = new Form; + $form['custom'] = $control = new CustomControl; + $control->getRules()->setRequired('required'); + $control->validate(); + Assert::same(['required'], $control->getErrors()); +}); + + +test('blank and valid conditions', function () { + $form = new Form; + $form['custom'] = $control = new CustomControl; + $control->setValue('x'); + $control->getRules() + ->addCondition(Form::Blank) + ->addRule(fn() => false, 'blank'); + $other = $form->addText('other')->setValue('y'); + $other->addConditionOn($control, Form::Valid) + ->addRule(fn() => false, 'valid'); + + $control->validate(); + $other->validate(); + Assert::same([], $control->getErrors()); + Assert::same(['valid'], $other->getErrors()); +}); From 2ec6fb39d1ea9579c5b4ffe3e2aba3c24210633c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 18:08:59 +0100 Subject: [PATCH 17/18] Validator: %value shows file names, list items and dates [Closes #302] --- src/Forms/Validator.php | 19 +++++- tests/Forms/Rules.formatMessage.value.phpt | 68 ++++++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/Forms/Rules.formatMessage.value.phpt diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index bfe1741e5..ac1132e97 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -88,7 +88,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string return ''; case 'value': return $withValue - ? $rule->control->getValue() + ? self::formatValue($rule->control, $rule->control->getValue()) : $m[0]; default: $args = is_array($rule->arg) ? $rule->arg : [$rule->arg]; @@ -97,7 +97,7 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string if ($arg === null) { return ''; } elseif ($arg instanceof Control) { - return $withValue ? $args[$i]->getValue() : "%$i"; + return $withValue ? self::formatValue($arg, $arg->getValue()) : "%$i"; } elseif ($rule->control instanceof Controls\DateTimeControl) { return $rule->control->formatLocaleText($arg); } else { @@ -109,6 +109,21 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string } + /** + * Formats a control value for a human-readable error message. + */ + private static function formatValue(Control $control, mixed $value): string + { + return match (true) { + is_array($value) => implode(', ', array_map(fn($item) => self::formatValue($control, $item), $value)), + $value instanceof Nette\Http\FileUpload => $value->getUntrustedName(), + $value instanceof \DateTimeInterface && $control instanceof Controls\DateTimeControl => $control->formatLocaleText($value), + $value instanceof \DateTimeInterface => $value->format('Y-m-d H:i:s'), + default => (string) $value, + }; + } + + /********************* default validators ****************d*g**/ diff --git a/tests/Forms/Rules.formatMessage.value.phpt b/tests/Forms/Rules.formatMessage.value.phpt new file mode 100644 index 000000000..a7eda219f --- /dev/null +++ b/tests/Forms/Rules.formatMessage.value.phpt @@ -0,0 +1,68 @@ +addCheckboxList('list', null, ['a' => 'A', 'b' => 'B']) + ->setDefaultValue(['a', 'b']) + ->addRule(Form::MaxLength, 'Too many: %value', 1); + + $form->validate(); + Assert::same(['Too many: a, b'], $form->getErrors()); +}); + + +test('date value', function () { + $form = new Form; + $form->addDate('date') + ->setDefaultValue('2023-10-22') + ->addRule(Form::Max, '%value is too late', new DateTime('2020-01-01')); + + $form->validate(); + Assert::count(1, $form->getErrors()); + Assert::match('%a%2023 is too late', $form->getErrors()[0]); +}); + + +test('uploaded file shows its name, not the temporary path', function () { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_FILES = [ + 'single' => [ + 'name' => 'doc.html', + 'type' => 'text/html', + 'tmp_name' => __DIR__ . '/../Controls/files/logo.gif', + 'error' => 0, + 'size' => 100, + ], + 'multi' => [ + 'name' => ['a.html', 'b.html'], + 'type' => ['text/html', 'text/html'], + 'tmp_name' => [__DIR__ . '/../Controls/files/logo.gif', __DIR__ . '/../Controls/files/logo.gif'], + 'error' => [0, 0], + 'size' => [100, 100], + ], + ]; + + Form::initialize(true); + + $form = new Form; + $form->allowCrossOrigin(); + $form->addUpload('single') + ->addRule(Form::MimeType, 'Unsupported %value.', 'text/plain'); + $form->addMultiUpload('multi') + ->addRule(Form::MimeType, 'Unsupported %value.', 'text/plain'); + + $form->validate(); + Assert::same(['Unsupported doc.html.', 'Unsupported a.html, b.html.'], $form->getErrors()); +}); From 917696a769a794cc3ae0b6212da07c21d95bc521 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Oct 2026 18:09:34 +0100 Subject: [PATCH 18/18] typo --- src/Forms/Form.php | 2 +- tests/Forms/Forms.maxPostSize.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 9380ffb19..87af694da 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -605,7 +605,7 @@ public function validateMaxPostSize(): void $maxSize = Helpers::iniGetSize('post_max_size'); if ($maxSize > 0 && $maxSize < $_SERVER['CONTENT_LENGTH']) { - $this->addError(sprintf(Validator::$messages[self::MaxFileSize], $maxSize)); + $this->addError(sprintf(Validator::$messages[self::MaxPostSize], $maxSize)); } } diff --git a/tests/Forms/Forms.maxPostSize.phpt b/tests/Forms/Forms.maxPostSize.phpt index 6242d5d68..4167fc28e 100644 --- a/tests/Forms/Forms.maxPostSize.phpt +++ b/tests/Forms/Forms.maxPostSize.phpt @@ -20,4 +20,4 @@ $form->isSuccess(); $errors = $form->getErrors(); Assert::count(1, $errors); -Assert::match('The size of the uploaded file can be up to %d% bytes.', $errors[0]); +Assert::match('The uploaded data exceeds the limit of %d% bytes.', $errors[0]);