Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplier: Add missing param typehint to getValues #94

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"php": ">=8.0",
"nette/forms": "^3.1.0"
"nette/forms": "^3.1.12"
},
"require-dev": {
"codeception/codeception": "^4.1.9",
Expand Down
13 changes: 8 additions & 5 deletions src/Multiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@

private bool $attachedCalled = false;

/** @var ComponentResolver */

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.
protected ComponentResolver $resolver;

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

public function __construct(callable $factory, int $copyNumber = 1, ?int $maxCopies = null)
{
Expand Down Expand Up @@ -213,7 +213,7 @@

public function createCopies(bool $forceValues = false): void
{
if ($this->created === true) {

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.
return;
}
$this->created = true;
Expand All @@ -236,7 +236,7 @@
$this->totalCopies >= $this->minCopies &&
!$this->resolver->reachedMinLimit()
) {
$this->form->setSubmittedBy($this->removeButton->create($this));

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

$this->resetFormEvents();

Expand Down Expand Up @@ -277,23 +277,26 @@
}

/**
* @param string|object|bool|null $returnType 'array' for array
* @param Control[]|null $controls
* @return object|mixed[]
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint
*/
public function getValues($returnType = null, ?array $controls = null): object|array

Check failure on line 284 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Method \Contributte\FormMultiplier\Multiplier::getValues() does not have native type hint for its parameter $returnType but it should be possible to add it based on @param annotation "string|object|bool|null".
{
if (!$this->resetKeys) {
return parent::getValues($returnType, $controls);
}

/** @var mixed[] $values */
$values = parent::getValues('array', $controls);
$values = parent::getValues(self::Array, $controls);
$values = array_values($values);

$returnType = $returnType === true ? 'array' : $returnType; // @phpstan-ignore-line nette backwards compatibility
if ($returnType === true) {
trigger_error(static::class . '::' . __FUNCTION__ . "(true) is deprecated, use getValues('array').", E_USER_DEPRECATED);
$returnType = self::Array;
}

return $returnType === 'array' ? $values : ArrayHash::from($values);
return $returnType === self::Array ? $values : ArrayHash::from($values);
}

/**
Expand Down Expand Up @@ -338,7 +341,7 @@

$this->created = false;
$this->detachCreateButtons();
$this->resolver = new ComponentResolver($this->values, $this->maxCopies, $this->minCopies);

Check failure on line 344 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed
$this->createCopies();
}

Expand Down Expand Up @@ -386,8 +389,8 @@
protected function loadHttpData(): void
{
if ($this->isFormSubmitted()) {
$httpData = Arrays::get($this->form->getHttpData(), $this->getHtmlName(), []);

Check failure on line 392 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 392 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed
$this->resolver = new ComponentResolver($httpData ?? [], $this->maxCopies, $this->minCopies);

Check failure on line 393 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed
}
}

Expand All @@ -411,7 +414,7 @@
*/
protected function getHtmlName(): array
{
return explode('-', $this->lookupPath(Form::class) ?? '');

Check failure on line 417 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Expression on left side of ?? is not nullable.
}

protected function createContainer(): Container
Expand Down Expand Up @@ -453,7 +456,7 @@
private function createComponents(bool $forceValues = false): void
{
$containers = [];
$containerDefaults = $this->createContainer()->getValues('array');
$containerDefaults = $this->createContainer()->getValues(self::Array);

// Components from httpData
if ($this->isFormSubmitted() && !$forceValues) {
Expand Down
Loading