PHPStan can't find the classes I installed with pear.
Why? How can I fix it?
pear install HTTP_Request2-2.5.1
pear config-get php_dir
/usr/share/pear
php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php => .:/usr/share/pear:/usr/share/php
ls -l /usr/share/pear/HTTP/Request2.php
-rw-r--r--. 1 root root 36102 Aug 19 11:38 /usr/share/pear/HTTP/Request2.php
test.php
<?php
require_once 'HTTP/Request2.php';
$request = new \HTTP_Request2("http://example.com");
phpstan analyze test.php
------ ---------------------------------------------------------------------
Line test.php
------ ---------------------------------------------------------------------
5 Instantiated class HTTP_Request2 not found.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
------ ---------------------------------------------------------------------
You have to specify the PEAR library path using phpstan.neon
config file.
parameters:
scanDirectories:
- /usr/share/pear
level: 5
$ phpstan analyze -c path/to/phpstan.neon test.php
Since your PEAR library HTTP_Request2
has not been installed via composer, PHPStan doesn't aware where it's from.
It seems PHPStan doesn't care include_path
intentionally.