/
MethodCallProhibitionAnalyzer.php
72 lines (64 loc) · 2.06 KB
/
MethodCallProhibitionAnalyzer.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Psalm\Internal\Analyzer\Statements\Expression\Call\Method;
use Psalm\CodeLocation;
use Psalm\Codebase;
use Psalm\Context;
use Psalm\Internal\Analyzer\NamespaceAnalyzer;
use Psalm\Internal\MethodIdentifier;
use Psalm\Issue\DeprecatedMethod;
use Psalm\Issue\InternalMethod;
use Psalm\IssueBuffer;
/**
* @internal
*/
class MethodCallProhibitionAnalyzer
{
/**
* @param string[] $suppressed_issues
*
* @return false|null
*/
public static function analyze(
Codebase $codebase,
Context $context,
MethodIdentifier $method_id,
?string $namespace,
CodeLocation $code_location,
array $suppressed_issues
): ?bool {
$codebase_methods = $codebase->methods;
$method_id = $codebase_methods->getDeclaringMethodId($method_id);
if ($method_id === null) {
return null;
}
$storage = $codebase_methods->getStorage($method_id);
if ($storage->deprecated) {
IssueBuffer::maybeAdd(
new DeprecatedMethod(
'The method ' . $codebase_methods->getCasedMethodId($method_id) .
' has been marked as deprecated',
$code_location,
(string) $method_id
),
$suppressed_issues
);
}
if (!$context->collect_initializations
&& !$context->collect_mutations
) {
if (!NamespaceAnalyzer::isWithin($namespace ?: '', $storage->internal)) {
IssueBuffer::maybeAdd(
new InternalMethod(
'The method ' . $codebase_methods->getCasedMethodId($method_id)
. ' is internal to ' . $storage->internal
. ' but called from ' . ($context->self ?: 'root namespace'),
$code_location,
(string) $method_id
),
$suppressed_issues
);
}
}
return null;
}
}