Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
"ecs": "php ./vendor/bin/ecs",
"rector": "php ./vendor/bin/rector process --dry-run --ansi",
"test": "php ./vendor/bin/tester -s -p php --colors 1 -C ./tests/Replicator",
"ci": "[\"@lint\", \"@phpstan\", \"@ecs\", \"@rector\", \"@test\"]"
"ci": [
"@lint",
"@phpstan",
"@ecs",
"@rector",
"@test"
]
}
}
14 changes: 0 additions & 14 deletions phpstan-baseline.neon

This file was deleted.

47 changes: 46 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,55 @@ includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- phpstan-baseline.neon

parameters:
level: max
paths:
- src/
treatPhpDocTypesAsCertain: false

ignoreErrors:
-
message: '''
#^Call to deprecated method attached\(\) of class Kdyby\\Replicator\\Container\:
use monitor\(\$type, \$attached\)$#
'''
identifier: method.deprecated
count: 2
# Only occurs with phpstan/phpstan-deprecation-rules ≥ 2.0.2 and nette/component-model ≥ 3.0.0 and < 4.0.0
reportUnmatched: false
path: src/Replicator/Container.php

# https://github.com/phpstan/phpstan-nette/issues/141
-
message: '#^Instanceof between Nette\\ComponentModel\\IComponent and Nette\\ComponentModel\\IComponent will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
# Only occurs with component-model < 4.0.0
reportUnmatched: false
count: 2
path: src/Replicator/Container.php

-
message: '#^Parameter \#1 \$array of function array_filter expects array, Iterator\<int\|string, Nette\\ComponentModel\\IComponent\> given\.$#'
identifier: argument.type
# Only occurs with component-model < 4.0.0
reportUnmatched: false
count: 3
path: src/Replicator/Container.php

-
message: '#^Parameter \#1 \$array of function array_filter expects array, Iterator\<int\|string, Nette\\ComponentModel\\IComponent\>\|list\<Nette\\ComponentModel\\IComponent\> given\.$#'
identifier: argument.type
# Only occurs with component-model < 4.0.0
reportUnmatched: false
count: 2
path: src/Replicator/Container.php

-
# https://github.com/nette/forms/pull/354
message: '#^Parameter \#2 \$callback of static method Nette\\Forms\\Container\:\:extensionMethod\(\) expects callable\(static\)\: mixed, Closure\(Nette\\Forms\\Container, string, callable, int\=, bool\=\)\: static given\.$#'
identifier: argument.type
# Only occurs with forms ≥ 3.3.0
reportUnmatched: false
count: 1
path: src/Replicator/Container.php
21 changes: 11 additions & 10 deletions src/Replicator/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Container extends Nette\Forms\Container
*/
public function __construct(callable $factory, int $createDefault = 0, bool $forceDefault = FALSE)
{
$this->monitor(Nette\Application\UI\Presenter::class);
$this->monitor(Nette\Forms\Form::class);
$this->monitor(Nette\Forms\Form::class, $this->attached(...));
$this->monitor(Nette\Application\UI\Presenter::class, $this->attached(...));

try {
$this->factoryCallback = Closure::fromCallable($factory);
Expand All @@ -94,8 +94,6 @@ public function setFactory(callable $factory): void
*/
protected function attached(Nette\ComponentModel\IComponent $obj): void
{
parent::attached($obj);

if (
!$obj instanceof Nette\Application\UI\Presenter
&&
Expand Down Expand Up @@ -143,14 +141,15 @@ protected function createComponent(string $name): ?Nette\ComponentModel\ICompone

($this->factoryCallback)($container);

return $this->created[$container->name] = $container;
return $this->created[$container->getName()] = $container;
}

private function getFirstControlName(): ?string
{
// TODO: The first instanceof check should be redundant but PHPStan infers getComponent() returns untyped array.
$controls = array_filter(
$this->getComponents(),
fn ($component): bool => $component instanceof Nette\Forms\Control,
fn ($component): bool => $component instanceof Nette\ComponentModel\IComponent && $component instanceof Nette\Forms\Control,
);
$firstControl = reset($controls);

Expand Down Expand Up @@ -274,8 +273,8 @@ private function getHttpData(): ?array
*/
public function remove(Nette\ComponentModel\Container $container, bool $cleanUpGroups = FALSE): void
{
if ($container->parent !== $this) {
throw new Nette\InvalidArgumentException('Given component ' . $container->name . ' is not children of ' . $this->name . '.');
if ($container->getParent() !== $this) {
throw new Nette\InvalidArgumentException('Given component ' . $container->getName() . ' is not children of ' . $this->getName() . '.');
}

// to check if form was submitted by this one
Expand Down Expand Up @@ -379,9 +378,11 @@ public function countFilledWithout(array $components = [], array $subComponents
public function isAllFilled(array $exceptChildren = []): bool
{
$components = [];

// TODO: The first instanceof check should be redundant but PHPStan infers getComponent() returns untyped array.
$controls = array_filter(
$this->getComponents(),
fn ($component): bool => $component instanceof Nette\Forms\Control,
fn ($component): bool => $component instanceof Nette\ComponentModel\IComponent && $component instanceof Nette\Forms\Control,
);
foreach ($controls as $control) {
if (($name = $control->getName()) !== null) {
Expand Down Expand Up @@ -452,7 +453,7 @@ function (Nette\Forms\Controls\SubmitButton $_this, ?callable $callback = NULL)
$_this->onClick[] = function (Nette\Forms\Controls\SubmitButton $button) use ($callback) {
/** @var self $replicator */
$replicator = $button->lookup(static::class);
$container = $button->parent;
$container = $button->getParent();
\assert($container instanceof Nette\ComponentModel\Container);
if (is_callable($callback)) {
$callback($replicator, $container);
Expand Down
Loading