-
-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathPhpStanFunctionMapReader.php
More file actions
43 lines (36 loc) · 1.24 KB
/
PhpStanFunctionMapReader.php
File metadata and controls
43 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace Safe\PhpStanFunctions;
use Safe\Generator\FileCreator;
use Safe\Templating\Filesystem;
class PhpStanFunctionMapReader
{
/**
* @var array<string, string[]>
*/
private $functionMap;
/**
* @var array<string, string[]>
*/
private $customFunctionMap;
public function __construct()
{
$this->functionMap = require 'phar://' . Filesystem::generatorDir() . '/vendor/phpstan/phpstan/phpstan.phar/resources/functionMap.php';
$this->customFunctionMap = require Filesystem::generatorDir() . '/config/CustomPhpStanFunctionMap.php';
}
public function getFunction(string $functionName): ?PhpStanFunction
{
if (!isset($this->functionMap[$functionName])) {
return null;
}
$map = $this->functionMap[$functionName];
$customMap = $this->customFunctionMap[$functionName] ?? null;
if ($map && $customMap) {
if ($customMap === $map) {
throw new \RuntimeException("Useless custom function map $functionName: ".var_export($customMap, true)."\nPlease delete this line from the custom file");
}
$map = $customMap;
}
return new PhpStanFunction($map);
}
}