Authentication and Authorization use dynamic properties in the controllers, like this for example:
$this->Authentication->addUnauthenticatedActions(['display']);
But PHPStan is obviously not happy with this:
Access to an undefined property App\Controller\PagesController::$Authorization.
How can i handle this, so PHPStan is happy with it?
Add property annotations above the AppController like so:
/**
* Application Controller
*
* @property \Authentication\Controller\Component\AuthenticationComponent $Authentication
* @property \Authorization\Controller\Component\AuthorizationComponent $Authorization
*/
class AppController extends Controller
{
// Rest of the AppController
}
But Iād rather recommend you take a look at GitHub - dereuromark/cakephp-ide-helper: IDE Helper plugin for CakePHP which can automatically add those annotations (and many others) to your code.
Also (for higher stan levels) you will need GitHub - CakeDC/cakephp-phpstan: CakePHP 4 extension for PHPStan
1 Like
Thank you very much for your help.