1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-13 01:37:23 +01:00
psalm/tests/Config/Plugin/Hook/FileProvider.php
lhchavez ab3016af6e
Fix File-related analysis plugin hooks (#3970)
This change does a few things:

* Renames `BeforeAnalyzeFileInterface` to `BeforeFileAnalysisInterface`.
* Adds a few more parameters to `BeforeFileAnalysisInterface`.
* Since the analysis was never called due to a bug, the above two
  changes are safe to do.
* Fix the above-mentioned bug, and now adds the hooks to the config.
* Update the documentation about the File-related analysis plugin hooks.
* Add a test to ensure that this does not break again in the future.

Fixes: #3969
2020-08-10 10:49:53 -04:00

45 lines
1.2 KiB
PHP

<?php
namespace Psalm\Test\Config\Plugin\Hook;
use Psalm\Codebase;
use Psalm\Context;
use Psalm\Plugin\Hook\AfterFileAnalysisInterface;
use Psalm\Plugin\Hook\BeforeFileAnalysisInterface;
use Psalm\StatementsSource;
use Psalm\Storage\FileStorage;
class FileProvider implements
AfterFileAnalysisInterface,
BeforeFileAnalysisInterface
{
/**
* Called before a file has been checked
*
* @return void
*/
public static function beforeAnalyzeFile(
StatementsSource $statements_source,
Context $file_context,
FileStorage $file_storage,
Codebase $codebase
) {
$file_storage = $codebase->file_storage_provider->get($statements_source->getFilePath());
$file_storage->custom_metadata['before-analysis'] = true;
}
/**
* Called before a file has been checked
*
* @return void
*/
public static function afterAnalyzeFile(
StatementsSource $statements_source,
Context $file_context,
FileStorage $file_storage,
Codebase $codebase
) {
$file_storage = $codebase->file_storage_provider->get($statements_source->getFilePath());
$file_storage->custom_metadata['after-analysis'] = true;
}
}