Skip to content

Updated AbstractActionController::indexAction return type to reflect real usage #5

Closed as not planned
@weierophinney

Description

@weierophinney
  • Is this related to quality assurance?

When running static analysis against a simple userland controller like:

class MyController extends AbstractActionController
{
    public function indexAction()
    {
        return ['posts' => ['foo', 'bar']];
    }
}

That do NOT provide the return type, neither with PHP 7.1 return type nor via DocBlock, tools like PHPstan use inherited docs and report:

Method MyController::indexAction() should return Zend\View\Model\ViewModel but returns array.

Of course users should add return types, but it would result in requiring a massive code update without real benefits, since the default behavior of Zend\Mvc framework is to allow:

  1. null from \Zend\Mvc\View\Http\CreateViewModelListener::createViewModelFromNull listener
  2. array from \Zend\Mvc\View\Http\CreateViewModelListener::createViewModelFromArray listener
  3. ViewModel from \Zend\Mvc\View\Http\DefaultRenderingStrategy::render listener
  4. ResponseInterface from \Zend\Mvc\SendResponseListener::sendResponse listener

This change only applies to indexAction since I guess its usage is widespread: notFoundAction is untouched as users that override it are, IMHO, already advanced ones.

Ping @Ocramius you type lover ❤️

Reference: https://github.com/Slamdunk/phpstan-zend-framework/issues/5


Originally posted by @Slamdunk at zendframework/zend-mvc#312

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions