Hey,
I’m trying to setup Psalm for my app and get a lot of errors like
composer require --dev nextcloud/ocp:dev-stable30
composer run psalm
ERROR: UndefinedClass - lib/Command/Run.php:24:19 - Class, interface or enum named OC\Core\Command\Base does not exist (see https://psalm.dev/019)
class Run extends Base {
ERROR: UndefinedClass - lib/Controller/BackgroundJobController.php:29:39 - Class, interface or enum named OCP\AppFramework\Controller does not exist (see https://psalm.dev/019)
class BackgroundJobController extends Controller {
ERROR: UndefinedClass - lib/Controller/SettingsController.php:27:34 - Class, interface or enum named OCP\AppFramework\Controller does not exist (see https://psalm.dev/019)
class SettingsController extends Controller {
ERROR: UndefinedClass - lib/Cron/Cleanup.php:23:23 - Class, interface or enum named OCP\BackgroundJob\TimedJob does not exist (see https://psalm.dev/019)
class Cleanup extends TimedJob {
ERROR: UndefinedDocblockClass - lib/Service/CleanupService.php:25:11 - Docblock-defined class, interface or enum named OCP\IDBConnection does not exist (see https://psalm.dev/200)
/** @var IDBConnection */
ERROR: UndefinedDocblockClass - lib/Service/CleanupService.php:28:11 - Docblock-defined class, interface or enum named OCP\ILogger does not exist (see https://psalm.dev/200)
/** @var ILogger */
[...]
I have the default minimal psalm config
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="5"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<!-- errorBaseline="tests/psalm-baseline.xml" -->
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<directory name="vendor" />
<!-- <directory name="lib/Vendor" /> -->
</ignoreFiles>
</projectFiles>
<extraFiles>
<directory name="vendor" />
<ignoreFiles>
<!-- <directory name="vendor/phpunit/php-code-coverage" /> -->
</ignoreFiles>
</extraFiles>
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="OC" />
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
<referencedClass name="Doctrine\DBAL\Driver\Statement" />
<referencedClass name="Doctrine\DBAL\Schema\Table" />
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
</psalm>
and this is my composer.json
{
"name": "synyx/cleanup",
"type": "project",
"license": "AGPLv3",
"require-dev": {
"nextcloud/coding-standard": "^1.2",
"psalm/phar": "^5.26.1"
},
"config": {
"platform": {
"php": "8.1"
},
"optimize-autoloader": true,
"classmap-authoritative": true,
"sort-packages": true,
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"autoload-dev": {
"psr-4": {
"OCA\\Cleanup\\": "lib/"
}
},
"require": {
"php": ">=8.0 <=8.3",
"bamarni/composer-bin-plugin": "^1.8",
"dekor/php-array-table": "^2.0",
"nesbot/carbon": "^2.72"
},
"scripts": {
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"lint": "find . -name \\*.php -not -path './vendor*/*' -print0 | xargs -0 -n1 php -l",
"psalm": "psalm.phar",
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
"post-install-cmd": [
"@composer bin all install --ansi",
"composer dump-autoload"
],
"post-update-cmd": [
"@composer bin all update --ansi",
"composer dump-autoload"
]
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
}
}
Best regards
Jonas