1

I have an CodeIgniter 4 application, and I am using PHPStan to help me with static analysis. My problem is that PHPStan complain that he can not find the CodeIgniter 4 functions. I check the PHPStan documentation, and I have this phpstan.neon configuration:

parameters:
level: 5
paths:
    - app\Models\IonAuthModel.php
scanDirectories:
    - app\config
    - app\controllers
    - app\database
    - app\filters
    - app\helpers
    - app\language
    - app\libraries
    - app\models
    - app\thirdparty
    - app\views
excludePaths:
    - app\models\IonAuthModel.php
    - app\controllers\Auth.php
    - app\controllers\Migrate.php
ignoreErrors:
    - '#Function view not found.#'
    - '#Function base_url not found.#'
    - '#Function redirect not found.#'
    - '#Function config not found.#'
    - '#Function helper not found.#'

As you can see I have been forced to add some of the errors in ignoreErrors, but list is growing. Now I have error about the lang method:

$output[] = lang($message) !== $message ? lang($message) : '##' . $message . '##';

but according to Codeigniter 4, lang method is correctly used here, and PHPStorm has no complain about this method. However, PHPStan gives the error:

Function lang not found. 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols

But I readed three times the link above and I can stil not resolve the issue with CodeIgniter function not found by PHPStan. Can anyone tell me what I am doing wrong?

1 Answer 1

1

These functions are defined here: https://github.com/codeigniter4/framework/blob/master/system/Common.php

So you'd need to put this file in your project into "discovering symbols"-related config parameters.

Also what might be sufficient to do instead: Put this file https://github.com/codeigniter4/framework/blob/master/system/bootstrap.php into bootstrapFiles in your phpstan.neon.

Also there are some old GitHub issues on analysing CodeIgniter projects with PHPStan, check them out, they link some repositories with sample configuration:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.