1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-17 03:47:04 +01:00
psalm/docs/running_psalm/checking_non_php_files.md
Oliver Hader e457a7d5af
[FEATURE] Allow plugins to declare their custom scanner or analyzer (#5883)
* [FEATURE] Allow plugins to declare their custom scanner or analyzer

Related: #5882

* [TEST] Check plugin declaring own scanner/analyzer

* [TASK] Document plugins declaring scanner or analyzer

* [TEST] Clean up code

* [!!!][TASK] Extend Psalm\Plugin\RegistrationInterface

* add method `addFileTypeScanner(string $fileExtension, string $className): void`
* add method `addFileTypeAnalyzer(string $fileExtension, string $className): void`

* [TASK] Ignore IntelliJ/PhpStorm workspace folder in VCS

* [TASK] Remove superfluous class import
2021-06-04 15:32:53 -04:00

1.2 KiB

Checking non-PHP files

Psalm supports the ability to check various PHPish files by extending the FileChecker class. For example, if you have a template where the variables are set elsewhere, Psalm can scrape those variables and check the template with those variables pre-populated.

An example TemplateChecker is provided here.

Using psalm.xml

To ensure your custom FileChecker is used, you must update the Psalm fileExtensions config in psalm.xml:

<fileExtensions>
    <extension name=".php" />
    <extension name=".phpt" checker="path/to/TemplateChecker.php" />
</fileExtensions>

Using custom plugin

Plugins can register their own custom scanner and analyzer implementations for particular file extensions.

<?php
namespace Psalm\Example;

use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;

class CustomPlugin implements PluginEntryPointInterface
{
    public function __invoke(RegistrationInterface $registration, ?\SimpleXMLElement $config = null): void
    {
        $registration->addFileTypeScanner('phpt', TemplateScanner::class);
        $registration->addFileTypeAnalyzer('phpt', TemplateAnalyzer::class);
    }
}