# How to handle PHPStan checks with Authentication and Authorization?

**URL:** <https://discourse.cakephp.org/t/how-to-handle-phpstan-checks-with-authentication-and-authorization/11421>\
**Category:** Need Help\
**Created:** [August 6, 2023, 8:04pm UTC](https://discourse.cakephp.org/t/how-to-handle-phpstan-checks-with-authentication-and-authorization/11421 "2023-08-06T20:04:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saturn93](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@Saturn93](https://discourse.cakephp.org/u/Saturn93)\
**Post date:** [August 6, 2023, 8:04pm UTC](https://discourse.cakephp.org/t/how-to-handle-phpstan-checks-with-authentication-and-authorization/11421/1 "2023-08-06T20:04:41Z")

</div>

Authentication and Authorization use dynamic properties in the controllers, like this for example:

```auto
        $this->Authentication->addUnauthenticatedActions(['display']);

```

But PHPStan is obviously not happy with this:

```auto
Access to an undefined property App\Controller\PagesController::$Authorization. 

```

How can i handle this, so PHPStan is happy with it?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 7, 2023, 5:21am UTC](https://discourse.cakephp.org/t/how-to-handle-phpstan-checks-with-authentication-and-authorization/11421/2 "2023-08-07T05:21:15Z")

</div>

Add property annotations above the AppController like so:

```php
/**
 * 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](https://github.com/dereuromark/cakephp-ide-helper) 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](https://github.com/CakeDC/cakephp-phpstan)

---

<div class="post-metadata">

**Author:** ![Saturn93](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@Saturn93](https://discourse.cakephp.org/u/Saturn93)\
**Post date:** [August 10, 2023, 1:56am UTC](https://discourse.cakephp.org/t/how-to-handle-phpstan-checks-with-authentication-and-authorization/11421/3 "2023-08-10T01:56:18Z")

</div>

Thank you very much for your help.
