PluginRegistrationSocket::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Psalm;
3
4
use Psalm\Plugin\Hook;
5
use Psalm\Plugin\RegistrationInterface;
6
use function class_exists;
7
use function is_subclass_of;
8
9
class PluginRegistrationSocket implements RegistrationInterface
10
{
11
    /** @var Config */
12
    private $config;
13
14
    /** @var Codebase */
15
    private $codebase;
16
17
    /**
18
     * @internal
19
     */
20
    public function __construct(Config $config, Codebase $codebase)
21
    {
22
        $this->config = $config;
23
        $this->codebase = $codebase;
24
    }
25
26
    /** @return void */
27
    public function addStubFile(string $file_name)
28
    {
29
        $this->config->addStubFile($file_name);
30
    }
31
32
    /**
33
     * @return void
34
     */
35
    public function registerHooksFromClass(string $handler)
36
    {
37
        if (!class_exists($handler, false)) {
38
            throw new \InvalidArgumentException('Plugins must be loaded before registration');
39
        }
40
41
        if (is_subclass_of($handler, Hook\AfterMethodCallAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
42
            $this->config->after_method_checks[$handler] = $handler;
43
        }
44
45
        if (is_subclass_of($handler, Hook\AfterFunctionCallAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
46
            $this->config->after_function_checks[$handler] = $handler;
47
        }
48
49
        if (is_subclass_of($handler, Hook\AfterEveryFunctionCallAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
50
            $this->config->after_every_function_checks[$handler] = $handler;
51
        }
52
53
        if (is_subclass_of($handler, Hook\AfterExpressionAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
54
            $this->config->after_expression_checks[$handler] = $handler;
55
        }
56
57
        if (is_subclass_of($handler, Hook\AfterStatementAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
58
            $this->config->after_statement_checks[$handler] = $handler;
59
        }
60
61
        if (is_subclass_of($handler, Hook\AfterClassLikeExistenceCheckInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...ceCheckInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
62
            $this->config->after_classlike_exists_checks[$handler] = $handler;
63
        }
64
65
        if (is_subclass_of($handler, Hook\AfterClassLikeAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
66
            $this->config->after_classlike_checks[$handler] = $handler;
67
        }
68
69
        if (is_subclass_of($handler, Hook\AfterClassLikeVisitInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...keVisitInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
70
            $this->config->after_visit_classlikes[$handler] = $handler;
71
        }
72
73
        if (is_subclass_of($handler, Hook\AfterCodebasePopulatedInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...pulatedInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
74
            $this->config->after_codebase_populated[$handler] = $handler;
75
        }
76
77
        if (is_subclass_of($handler, Hook\PropertyExistenceProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Prope...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
78
            $this->codebase->properties->property_existence_provider->registerClass($handler);
79
        }
80
81
        if (is_subclass_of($handler, Hook\PropertyVisibilityProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Prope...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
82
            $this->codebase->properties->property_visibility_provider->registerClass($handler);
83
        }
84
85
        if (is_subclass_of($handler, Hook\PropertyTypeProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Prope...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
86
            $this->codebase->properties->property_type_provider->registerClass($handler);
87
        }
88
89
        if (is_subclass_of($handler, Hook\MethodExistenceProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Metho...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
90
            $this->codebase->methods->existence_provider->registerClass($handler);
91
        }
92
93
        if (is_subclass_of($handler, Hook\MethodVisibilityProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Metho...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
94
            $this->codebase->methods->visibility_provider->registerClass($handler);
95
        }
96
97
        if (is_subclass_of($handler, Hook\MethodReturnTypeProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Metho...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
98
            $this->codebase->methods->return_type_provider->registerClass($handler);
99
        }
100
101
        if (is_subclass_of($handler, Hook\MethodParamsProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Metho...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
102
            $this->codebase->methods->params_provider->registerClass($handler);
103
        }
104
105
        if (is_subclass_of($handler, Hook\FunctionExistenceProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Funct...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
106
            $this->codebase->functions->existence_provider->registerClass($handler);
107
        }
108
109
        if (is_subclass_of($handler, Hook\FunctionParamsProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Funct...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
110
            $this->codebase->functions->params_provider->registerClass($handler);
111
        }
112
113
        if (is_subclass_of($handler, Hook\FunctionReturnTypeProviderInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Funct...roviderInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
114
            $this->codebase->functions->return_type_provider->registerClass($handler);
115
        }
116
117
        if (is_subclass_of($handler, Hook\AfterAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\AfterAnalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
118
            $this->config->after_analysis[$handler] = $handler;
119
        }
120
121
        if (is_subclass_of($handler, Hook\StringInterpreterInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\Strin...rpreterInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
122
            $this->config->string_interpreters[$handler] = $handler;
123
        }
124
125
        if (is_subclass_of($handler, Hook\AfterFunctionLikeAnalysisInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Psalm\Plugin\Hook\After...nalysisInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
126
            $this->config->after_functionlike_checks[$handler] = $handler;
127
        }
128
    }
129
}
130