Skip to content

Commit

Permalink
Fix phpdoc, remove psalm-suppress (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 5, 2022
1 parent 34af4b4 commit 0f60001
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Widget/Attribute/FieldAttributes.php
Expand Up @@ -616,7 +616,7 @@ protected function getDefaultTokens(): array
protected function getDefinitions(): array
{
$definitions = $this->getDefaultValue($this->type, 'definitions') ?? [];
return is_array($definitions) ? $definitions : [];
return is_array($definitions) ? $definitions : [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Widget/Attribute/GlobalAttributes.php
Expand Up @@ -169,13 +169,13 @@ public function title(string $value): static
/**
* The value content attribute gives the default value of the field.
*
* @param bool|float|int|iterable|object|string|null $value
* @param mixed $value
*
* @return static
*
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-value
*/
public function value(iterable|int|float|string|bool|object|null $value): static
public function value(mixed $value): static
{
$new = clone $this;
$new->attributes['value'] = $value;
Expand Down
4 changes: 0 additions & 4 deletions src/Widget/CheckboxList.php
Expand Up @@ -42,8 +42,6 @@ final class CheckboxList extends ChoiceAttributes
* @return static
*
* @link https://www.w3.org/TR/html52/sec-forms.html#autofocusing-a-form-control-the-autofocus-attribute
*
* @psalm-suppress MethodSignatureMismatch
*/
public function autofocus(): static
{
Expand Down Expand Up @@ -90,8 +88,6 @@ public function containerTag(?string $tag = null): self
* @return static
*
* @link https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute
*
* @psalm-suppress MethodSignatureMismatch
*/
public function id(?string $id): static
{
Expand Down
23 changes: 18 additions & 5 deletions src/Widget/ErrorSummary.php
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Form\Widget;

use InvalidArgumentException;
use Yiisoft\Form\Exception\FormModelNotSetException;
use Yiisoft\Form\FormModelInterface;
use Yiisoft\Form\Helper\HtmlFormErrors;
use Yiisoft\Html\Html;
Expand All @@ -20,15 +21,13 @@

/**
* The error summary widget displays a summary of the errors in a form.
*
* @psalm-suppress MissingConstructor
*/
final class ErrorSummary extends Widget
{
private array $attributes = [];
private bool $encode = true;
private array $onlyAttributes = [];
private FormModelInterface $formModel;
private ?FormModelInterface $formModel = null;
private string $footer = '';
private array $footerAttributes = [];
private string $header = 'Please fix the following errors:';
Expand Down Expand Up @@ -192,11 +191,11 @@ public function tag(string $value): self
*/
private function collectErrors(): array
{
$errors = HtmlFormErrors::getErrorSummaryFirstErrors($this->formModel);
$errors = HtmlFormErrors::getErrorSummaryFirstErrors($this->getFormModel());
$errorMessages = [];

if ($this->showAllErrors) {
$errors = HtmlFormErrors::getErrorSummary($this->formModel, $this->onlyAttributes);
$errors = HtmlFormErrors::getErrorSummary($this->getFormModel(), $this->onlyAttributes);
} elseif ($this->onlyAttributes !== []) {
$errors = array_intersect_key($errors, array_flip($this->onlyAttributes));
}
Expand Down Expand Up @@ -251,4 +250,18 @@ protected function run(): string
->render()
: '';
}

/**
* Return FormModelInterface object.
*
* @return FormModelInterface
*/
private function getFormModel(): FormModelInterface
{
if ($this->formModel === null) {
throw new FormModelNotSetException();
}

return $this->formModel;
}
}
4 changes: 0 additions & 4 deletions src/Widget/RadioList.php
Expand Up @@ -42,8 +42,6 @@ final class RadioList extends ChoiceAttributes
* @return static
*
* @link https://www.w3.org/TR/html52/sec-forms.html#autofocusing-a-form-control-the-autofocus-attribute
*
* @psalm-suppress MethodSignatureMismatch
*/
public function autofocus(): static
{
Expand Down Expand Up @@ -90,8 +88,6 @@ public function containerTag(?string $name = null): self
* @return static
*
* @link https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute
*
* @psalm-suppress MethodSignatureMismatch
*/
public function id(?string $id): static
{
Expand Down
11 changes: 11 additions & 0 deletions tests/Widget/ErrorSummaryTest.php
Expand Up @@ -10,6 +10,7 @@
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
use Yiisoft\Factory\NotFoundException;
use Yiisoft\Form\Exception\FormModelNotSetException;
use Yiisoft\Form\Tests\TestSupport\Form\PersonalForm;
use Yiisoft\Form\Tests\TestSupport\TestTrait;
use Yiisoft\Form\Widget\ErrorSummary;
Expand All @@ -18,6 +19,16 @@ final class ErrorSummaryTest extends TestCase
{
use TestTrait;

/**
* @throws CircularReferenceException|InvalidConfigException|NotFoundException|NotInstantiableException
*/
public function testGetFormModelException(): void
{
$this->expectException(FormModelNotSetException::class);
$this->expectExceptionMessage('Failed to create widget because form model is not set.');
$this->invokeMethod(ErrorSummary::widget(), 'getFormModel');
}

public function dataProviderErrorSummary(): array
{
return [
Expand Down

0 comments on commit 0f60001

Please sign in to comment.