Closed MatyCZ closed 3 years ago
I'd need a complete example of the code you're running, but you could for example leverage assert()
:
public function testAction() {
$request = $this->getRequest();
assert($request instanceof \Laminas\Http\Request);
if (!in_array($request->getMethod(), [Request::METHOD_POST])) {
throw new \Exception(...)
}
if ($request->isPost()) {
$post = $this->getPost();
}
}
This is example of the code:
<?php
namespace App\Controller;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class TestController extends AbstractActionController
{
public function updateAction(): ViewModel
{
if ($this->getRequest()->isPost()) {
$post = $this->getRequest()->getPost();
var_dump($post);
}
return new ViewModel([
'test' => true
]);
}
}
I solved this problem with phpstan config:
ignoreErrors:
- '#Call to an undefined method Laminas\\Console\\Request::getMethod\(\)#'
- '#Call to an undefined method Laminas\\Console\\Request::isPatch\(\)#'
- '#Call to an undefined method Laminas\\Console\\Request::isPost\(\)#'
- '#Call to an undefined method Laminas\\Console\\Response::getHeaders\(\)#'
PhpStan shows following errors after installation of phpstan-laminas-framework. The problem is that this Controller is never called from console (only phpstan is called from cli). Is there any option to set right class for method
getRequest()
?PhpStan output:
Example: