Skip to content
Open
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 src/Application/UI/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$throw = func_get_arg(0);
}

return $this->lookup(Presenter::class, throw: $throw ?? true);

Check failure on line 45 in src/Application/UI/Component.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Nette\Application\UI\Component::getPresenter() should return Nette\Application\UI\Presenter|null but returns Nette\ComponentModel\IComponent|null.
}


Expand Down Expand Up @@ -172,8 +172,14 @@
}

$this->$name = &$params[$name];
} else {
} elseif ($meta['hasDefault']) {
$params[$name] = &$this->$name;
} else {
throw new Nette\InvalidArgumentException(sprintf(
'Missing parameter $%s required by %s.',
$name,
$this instanceof Presenter ? "presenter {$this->getName()}" : "component '{$this->getUniqueId()}'",
));
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/Application/UI/ComponentReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class ComponentReflection extends \ReflectionClass

/**
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter].
* @return array<string, array{def: mixed, type: string, since: ?string}>
* @return array<string, array{def: mixed, type: string, since?: ?string, hasDefault: bool}>
*/
public function getParameters(): array
{
Expand All @@ -48,16 +48,20 @@ public function getParameters(): array
self::parseAnnotation($prop, 'persistent')
|| $prop->getAttributes(Attributes\Persistent::class)
) {
$params[$prop->getName()] = [
'def' => $prop->getDefaultValue(),
$param = [
'type' => ParameterConverter::getType($prop),
'since' => $isPresenter ? Reflection::getPropertyDeclaringClass($prop)->getName() : null,
];
} elseif ($prop->getAttributes(Attributes\Parameter::class)) {
$params[$prop->getName()] = [
$param = [
'type' => (string) ($prop->getType() ?? 'mixed'),
];
} else {
continue;
}
$param['def'] = $prop->getDefaultValue();
$param['hasDefault'] = $prop->hasDefaultValue();
$params[$prop->getName()] = $param;
}

if ($this->getParentClass()->isSubclassOf(Component::class)) {
Expand All @@ -77,7 +81,7 @@ public function getParameters(): array

/**
* Returns array of persistent properties. They are public and have attribute #[Persistent].
* @return array<string, array{def: mixed, type: string, since: string}>
* @return array<string, array{def: mixed, type: string, since: ?string, hasDefault: bool}>
*/
public function getPersistentParams(): array
{
Expand Down
Loading