2018-02-18 01:53:17 +01:00
# 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 ](https://github.com/vimeo/psalm/blob/master/examples/TemplateChecker.php ).
2021-06-04 21:32:53 +02:00
## Using `psalm.xml`
2018-02-18 01:53:17 +01:00
To ensure your custom `FileChecker` is used, you must update the Psalm `fileExtensions` config in psalm.xml:
```xml
< fileExtensions >
< extension name = ".php" / >
< extension name = ".phpt" checker = "path/to/TemplateChecker.php" / >
< / fileExtensions >
```
2021-06-04 21:32:53 +02:00
## Using custom plugin
Plugins can register their own custom scanner and analyzer implementations for particular file extensions.
```php
< ?php
namespace Psalm\Example;
use Psalm\Plugin\PluginEntryPointInterface;
2021-11-01 18:04:42 +01:00
use Psalm\Plugin\PluginFileExtensionsInterface;
use Psalm\Plugin\FileExtensionsInterface;
2021-06-04 21:32:53 +02:00
use Psalm\Plugin\RegistrationInterface;
2021-11-01 18:04:42 +01:00
class CustomPlugin implements PluginEntryPointInterface, PluginFileExtensionsInterface
2021-06-04 21:32:53 +02:00
{
public function __invoke(RegistrationInterface $registration, ?\SimpleXMLElement $config = null): void
{
2021-11-01 18:04:42 +01:00
// ... regular plugin processes, stub registration, hook registration
2021-06-04 21:32:53 +02:00
}
2021-11-01 18:04:42 +01:00
public function processFileExtensions(FileExtensionsInterface $fileExtensions, ?SimpleXMLElement $config = null): void
{
$fileExtensions->addFileTypeScanner('phpt', TemplateScanner::class);
$fileExtensions->addFileTypeAnalyzer('phpt', TemplateAnalyzer::class);
}
2021-06-04 21:32:53 +02:00
}
```