Skip to content

Commit d2bba38

Browse files
committed
cs
1 parent 8735ca2 commit d2bba38

File tree

12 files changed

+29
-35
lines changed

12 files changed

+29
-35
lines changed

src/Forms/Container.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
4949
*/
5050
public function setDefaults(array|object $data, bool $erase = false): static
5151
{
52-
$form = $this->getForm(false);
52+
$form = $this->getForm(throw: false);
5353
$this->setValues($data, $erase, $form?->isAnchored() && $form->isSubmitted());
5454
return $this;
5555
}
@@ -87,7 +87,7 @@ public function setValues(array|object $values, bool $erase = false, bool $onlyD
8787
*/
8888
public function getValues(string|object|bool|null $returnType = null, ?array $controls = null): object|array
8989
{
90-
$form = $this->getForm(false);
90+
$form = $this->getForm(throw: false);
9191
if ($form && ($submitter = $form->isSubmitted())) {
9292
if ($this->validated === null) {
9393
throw new Nette\InvalidStateException('You cannot call getValues() during the validation process. Use getUntrustedValues() instead.');
@@ -98,10 +98,10 @@ public function getValues(string|object|bool|null $returnType = null, ?array $co
9898

9999
if ($controls === null && $submitter instanceof SubmitterControl) {
100100
$controls = $submitter->getValidationScope();
101-
if ($controls !== null && !in_array($this, $controls, true)) {
101+
if ($controls !== null && !in_array($this, $controls, strict: true)) {
102102
$scope = $this;
103103
while (($scope = $scope->getParent()) instanceof self) {
104-
if (in_array($scope, $controls, true)) {
104+
if (in_array($scope, $controls, strict: true)) {
105105
$controls[] = $this;
106106
break;
107107
}
@@ -130,7 +130,7 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array
130130
$properties = (new \ReflectionClass($resultObj))->getProperties();
131131

132132
} else {
133-
$returnType = ($returnType ?? $this->mappedType ?? ArrayHash::class);
133+
$returnType ??= $this->mappedType ?? ArrayHash::class;
134134
$rc = new \ReflectionClass($returnType === self::Array ? \stdClass::class : $returnType);
135135
$constructor = $rc->hasMethod('__construct') ? $rc->getMethod('__construct') : null;
136136
if ($constructor?->getNumberOfRequiredParameters()) {
@@ -146,7 +146,7 @@ public function getUntrustedValues(string|object|null $returnType = null, ?array
146146
$properties = array_combine(array_map(fn($p) => $p->getName(), $properties), $properties);
147147

148148
foreach ($this->getComponents() as $name => $control) {
149-
$allowed = $controls === null || in_array($this, $controls, true) || in_array($control, $controls, true);
149+
$allowed = $controls === null || in_array($this, $controls, strict: true) || in_array($control, $controls, strict: true);
150150
$name = (string) $name;
151151
$property = $properties[$name] ?? null;
152152
if (

src/Forms/Controls/BaseControl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function setHtmlAttribute(string $name, mixed $value = true): static
325325
$this->control->$name = $value;
326326
if (
327327
$name === 'name'
328-
&& ($form = $this->getForm(false))
328+
&& ($form = $this->getForm(throw: false))
329329
&& !$this->isDisabled()
330330
&& $form->isAnchored()
331331
&& $form->isSubmitted()
@@ -365,7 +365,7 @@ public function setTranslator(?Nette\Localization\Translator $translator): stati
365365
public function getTranslator(): ?Nette\Localization\Translator
366366
{
367367
if ($this->translator === true) {
368-
return $this->getForm(false)
368+
return $this->getForm(throw: false)
369369
? $this->getForm()->getTranslator()
370370
: null;
371371
}

src/Forms/Controls/ChoiceControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class ChoiceControl extends BaseControl
2525
private array $items = [];
2626

2727

28-
public function __construct($label = null, ?array $items = null)
28+
public function __construct(string|\Stringable|null $label = null, ?array $items = null)
2929
{
3030
parent::__construct($label);
3131
if ($items !== null) {

src/Forms/Controls/ColorPicker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class ColorPicker extends BaseControl
2020
{
21-
public function __construct($label = null)
21+
public function __construct(string|\Stringable|null $label = null)
2222
{
2323
parent::__construct($label);
2424
$this->setOption('type', 'color');

src/Forms/Controls/DateTimeControl.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@ class DateTimeControl extends BaseControl
2828
public const
2929
FormatObject = 'object',
3030
FormatTimestamp = 'timestamp';
31-
32-
private int $type;
33-
private bool $withSeconds;
3431
private string $format = self::FormatObject;
3532

3633

3734
public function __construct(
3835
string|Stringable|null $label = null,
39-
int $type = self::TypeDate,
40-
bool $withSeconds = false,
36+
private int $type = self::TypeDate,
37+
private bool $withSeconds = false,
4138
) {
42-
$this->type = $type;
43-
$this->withSeconds = $withSeconds;
4439
parent::__construct($label);
4540
$this->control->step = $withSeconds ? 1 : null;
4641
$this->setOption('type', 'datetime');

src/Forms/Controls/MultiChoiceControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class MultiChoiceControl extends BaseControl
2525
private array $items = [];
2626

2727

28-
public function __construct($label = null, ?array $items = null)
28+
public function __construct(string|\Stringable|null $label = null, ?array $items = null)
2929
{
3030
parent::__construct($label);
3131
if ($items !== null) {

src/Forms/Controls/SelectBox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SelectBox extends ChoiceControl
3131
private array $optionAttributes = [];
3232

3333

34-
public function __construct($label = null, ?array $items = null)
34+
public function __construct(string|\Stringable|null $label = null, ?array $items = null)
3535
{
3636
parent::__construct($label, $items);
3737
$this->setOption('type', 'select');

src/Forms/Controls/TextInput.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getControl(): Nette\Utils\Html
5757
{
5858
return parent::getControl()->addAttributes([
5959
'value' => $this->control->type === 'password' ? $this->control->value : $this->getRenderedValue(),
60-
'type' => $this->control->type ?: 'text',
60+
'type' => $this->control->type ?? 'text',
6161
]);
6262
}
6363

@@ -74,13 +74,13 @@ public function addRule(
7474
}
7575
}
7676

77-
if ($this->control->type === null && in_array($validator, [Form::Email, Form::URL, Form::Integer], true)) {
77+
if ($this->control->type === null && in_array($validator, [Form::Email, Form::URL, Form::Integer], strict: true)) {
7878
$types = [Form::Email => 'email', Form::URL => 'url', Form::Integer => 'number'];
7979
$this->control->type = $types[$validator];
8080

8181
} elseif (
82-
in_array($validator, [Form::Min, Form::Max, Form::Range], true)
83-
&& in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], true)
82+
in_array($validator, [Form::Min, Form::Max, Form::Range], strict: true)
83+
&& in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], strict: true)
8484
) {
8585
if ($validator === Form::Min) {
8686
$range = [$arg, null];
@@ -105,7 +105,7 @@ public function addRule(
105105
} elseif (
106106
$validator === Form::Pattern
107107
&& is_scalar($arg)
108-
&& in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], true)
108+
&& in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], strict: true)
109109
) {
110110
$this->control->pattern = $arg;
111111
}

src/Forms/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ public static function initialize(bool $reinit = false): void
769769

770770
self::$defaultHttpRequest = (new Nette\Http\RequestFactory)->fromGlobals();
771771

772-
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
772+
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], strict: true)) {
773773
if (headers_sent($file, $line)) {
774774
throw new Nette\InvalidStateException(
775775
'Create a form or call Nette\Forms\Form::initialize() before the headers are sent to initialize CSRF protection.'

src/Forms/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static function sanitize(int $type, $value): string|array|Nette\Http\Fil
9494
*/
9595
public static function generateHtmlName(string $id): string
9696
{
97-
$name = str_replace(Nette\ComponentModel\IComponent::NAME_SEPARATOR, '][', $id, $count);
97+
$name = str_replace(Nette\ComponentModel\IComponent::NameSeparator, '][', $id, $count);
9898
if ($count) {
9999
$name = substr_replace($name, '', strpos($name, ']'), 1) . ']';
100100
}
@@ -319,6 +319,6 @@ public static function tryEnumConversion(mixed $value, $reflection): mixed
319319
/** @internal */
320320
public static function getSupportedImages(): array
321321
{
322-
return array_values(array_map(fn($type) => Image::typeToMimeType($type), Image::getSupportedTypes()));
322+
return array_values(array_map(Image::typeToMimeType(...), Image::getSupportedTypes()));
323323
}
324324
}

0 commit comments

Comments
 (0)