Skip to content

Commit fd59a6b

Browse files
committed
added PHP 8 typehints
1 parent 2c3f9e8 commit fd59a6b

26 files changed

+119
-226
lines changed

src/Bridges/FormsLatte/Runtime.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ public static function renderBlueprint($form): void
8686
public $inner;
8787

8888

89-
public function getLabel($name = null)
89+
public function getLabel($name = null): Html|string|null
9090
{
9191
return $this->inner->getLabel()
9292
? '{label ' . $this->inner->lookupPath(Form::class) . '/}'
9393
: null;
9494
}
9595

9696

97-
public function getControl()
97+
public function getControl(): Html|string
9898
{
9999
return '{input ' . $this->inner->lookupPath(Form::class) . '}';
100100
}
@@ -106,7 +106,7 @@ public function isRequired(): bool
106106
}
107107

108108

109-
public function getOption($key, $default = null)
109+
public function getOption($key, mixed $default = null): mixed
110110
{
111111
return $key === 'rendered'
112112
? parent::getOption($key)

src/Forms/Container.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
4747

4848
/**
4949
* Fill-in with default values.
50-
* @param array|object $data
51-
* @return static
5250
*/
53-
public function setDefaults($data, bool $erase = false)
51+
public function setDefaults(array|object $data, bool $erase = false): static
5452
{
5553
$form = $this->getForm(false);
5654
if (!$form || !$form->isAnchored() || !$form->isSubmitted()) {
@@ -62,20 +60,15 @@ public function setDefaults($data, bool $erase = false)
6260

6361
/**
6462
* Fill-in with values.
65-
* @param array|object $data
66-
* @return static
6763
* @internal
6864
*/
69-
public function setValues($data, bool $erase = false)
65+
public function setValues(array|object $data, bool $erase = false): static
7066
{
7167
if ($data instanceof \Traversable) {
7268
$values = iterator_to_array($data);
7369

7470
} elseif (is_object($data) || is_array($data) || $data === null) {
7571
$values = (array) $data;
76-
77-
} else {
78-
throw new Nette\InvalidArgumentException(sprintf('First parameter must be an array or object, %s given.', gettype($data)));
7972
}
8073

8174
foreach ($this->getComponents() as $name => $control) {
@@ -88,7 +81,7 @@ public function setValues($data, bool $erase = false)
8881
}
8982

9083
} elseif ($control instanceof self) {
91-
if (array_key_exists($name, $values)) {
84+
if (isset($values[$name])) {
9285
$control->setValues($values[$name], $erase);
9386

9487
} elseif ($erase) {
@@ -104,9 +97,8 @@ public function setValues($data, bool $erase = false)
10497
* Returns the values submitted by the form.
10598
* @param string|object|null $returnType 'array' for array
10699
* @param Control[]|null $controls
107-
* @return object|array
108100
*/
109-
public function getValues($returnType = null, array $controls = null)
101+
public function getValues(string|object|bool $returnType = null, array $controls = null): object|array
110102
{
111103
$form = $this->getForm(false);
112104
if ($form && ($submitter = $form->isSubmitted())) {
@@ -126,9 +118,8 @@ public function getValues($returnType = null, array $controls = null)
126118
* Returns the potentially unvalidated values submitted by the form.
127119
* @param string|object|null $returnType 'array' for array
128120
* @param Control[]|null $controls
129-
* @return object|array
130121
*/
131-
public function getUnsafeValues($returnType, array $controls = null)
122+
public function getUnsafeValues(string|object|null $returnType, array $controls = null): object|array
132123
{
133124
if (is_object($returnType)) {
134125
$obj = $returnType;
@@ -163,8 +154,7 @@ public function getUnsafeValues($returnType, array $controls = null)
163154
}
164155

165156

166-
/** @return static */
167-
public function setMappedType(string $type)
157+
public function setMappedType(string $type): static
168158
{
169159
$this->mappedType = $type;
170160
return $this;
@@ -229,8 +219,7 @@ public function getErrors(): array
229219
/********************* form building ****************d*g**/
230220

231221

232-
/** @return static */
233-
public function setCurrentGroup(ControlGroup $group = null)
222+
public function setCurrentGroup(ControlGroup $group = null): static
234223
{
235224
$this->currentGroup = $group;
236225
return $this;
@@ -248,11 +237,13 @@ public function getCurrentGroup(): ?ControlGroup
248237

249238
/**
250239
* Adds the specified component to the IContainer.
251-
* @return static
252240
* @throws Nette\InvalidStateException
253241
*/
254-
public function addComponent(Nette\ComponentModel\IComponent $component, ?string $name, string $insertBefore = null)
255-
{
242+
public function addComponent(
243+
Nette\ComponentModel\IComponent $component,
244+
?string $name,
245+
string $insertBefore = null,
246+
): static {
256247
parent::addComponent($component, $name, $insertBefore);
257248
if ($this->currentGroup !== null) {
258249
$this->currentGroup->add($component);
@@ -469,9 +460,8 @@ public function addImage(): Controls\ImageButton
469460

470461
/**
471462
* Adds naming container to the form.
472-
* @param string|int $name
473463
*/
474-
public function addContainer($name): self
464+
public function addContainer(string|int $name): self
475465
{
476466
$control = new self;
477467
$control->currentGroup = $this->currentGroup;

src/Forms/Control.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ interface Control
1717
{
1818
/**
1919
* Sets control's value.
20-
* @param mixed $value
21-
* @return static
2220
*/
23-
function setValue($value);
21+
function setValue(mixed $value): static;
2422

2523
/**
2624
* Returns control's value.
27-
* @return mixed
2825
*/
29-
function getValue();
26+
function getValue(): mixed;
3027

3128
function validate(): void;
3229

src/Forms/ControlGroup.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public function __construct()
3030
}
3131

3232

33-
/** @return static */
34-
public function add(...$items)
33+
public function add(...$items): static
3534
{
3635
foreach ($items as $item) {
3736
if ($item instanceof Control) {
@@ -84,10 +83,8 @@ public function getControls(): array
8483
* - 'container' - container as Html object
8584
* - 'description' - textual or Nette\HtmlStringable object description
8685
* - 'embedNext' - describes how render next group
87-
*
88-
* @return static
8986
*/
90-
public function setOption(string $key, $value)
87+
public function setOption(string $key, mixed $value): static
9188
{
9289
if ($value === null) {
9390
unset($this->options[$key]);
@@ -101,9 +98,8 @@ public function setOption(string $key, $value)
10198

10299
/**
103100
* Returns user-specific option.
104-
* @return mixed
105101
*/
106-
public function getOption(string $key, $default = null)
102+
public function getOption(string $key, $default = null): mixed
107103
{
108104
return $this->options[$key] ?? $default;
109105
}

0 commit comments

Comments
 (0)