yiisoft / demo

Yii 3 demo application
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
316 stars 132 forks source link

Incorrect attribute in `blog/src/User/Controller/UserController.php` #593

Closed xepozz closed 11 months ago

xepozz commented 1 year ago
image

https://github.com/yiisoft/demo/blob/master/blog/src/User/Controller/UserController.php#L28

The method type is GET, it's impossible to access the body

image
vjik commented 1 year ago

Seems, here will be enough just remove #[Body] array $body and don't use it in action.

rossaddison commented 11 months ago

Yes the index function is relevant to an index and there is no $body parameter being passed in the action, as part of parameters; the $body parameter being passed to forms normally as part of the $parameter array in the controller function. Substituting the mixed type instead of array allows the demo to run since $body is actually carrying a null value and $body when VarDumped through a parameter in the controller onto the index shows a null value anyway.

rossaddison commented 11 months ago

The pageSize will have to be accessed via route only though since $body['pageSize] is carrying no value since $body is null.

rossaddison commented 11 months ago

How reliable is the OffsetPaginator as I am getting the following results under psalm level 1:

ERROR: MissingConstructor - src/Widget/OffsetPagination.php:18:17 - App\Widget\OffsetPagination has an uninitialized property App\Widget\OffsetPagination::$pagesCount, but no constructor (see https://psalm.dev/073)
    private int $pagesCount;

ERROR: MissingConstructor - src/Widget/OffsetPagination.php:19:17 - App\Widget\OffsetPagination has an uninitialized property App\Widget\OffsetPagination::$currentPage, but no constructor (see https://psalm.dev/073)
    private int $currentPage;

ERROR: MissingConstructor - src/Widget/OffsetPagination.php:20:19 - App\Widget\OffsetPagination has an uninitialized property App\Widget\OffsetPagination::$pages, but no constructor (see https://psalm.dev/073)
    private array $pages;

ERROR: MissingConstructor - src/Widget/OffsetPagination.php:21:18 - App\Widget\OffsetPagination has an uninitialized property App\Widget\OffsetPagination::$prepared, but no constructor (see https://psalm.dev/073)
    private bool $prepared;

ERROR: PossiblyNullReference - src/Widget/OffsetPagination.php:81:47 - Cannot call method getTotalPages on possibly null value (see https://psalm.dev/083)
        $this->pagesCount = $this->paginator->getTotalPages();

ERROR: PossiblyNullReference - src/Widget/OffsetPagination.php:112:38 - Cannot call method isOnFirstPage on possibly null value (see https://psalm.dev/083)
        $prevUrl = $this->paginator->isOnFirstPage() ? null : $this->getPageLink($this->currentPage - 1);

ERROR: MixedAssignment - src/Widget/OffsetPagination.php:118:34 - Unable to determine the type that $page is being assigned to (see https://psalm.dev/032)
        foreach ($this->pages as $page) {

ERROR: MixedArgument - src/Widget/OffsetPagination.php:124:71 - Argument 1 of App\Widget\OffsetPagination::getPageLink cannot be int|mixed, expecting int (see https://psalm.dev/030)
                $result .= Html::a((string) $page, $this->getPageLink($page), ['class' => 'page-link']);
vjik commented 11 months ago

Fixed by https://github.com/yiisoft/demo/pull/599