Conditions | 11 |
Paths | 32 |
Total Lines | 68 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
91 | private function resolveIntegrationsFromUserConfig(): array |
||
92 | { |
||
93 | // Default Sentry SDK integrations |
||
94 | $integrations = [ |
||
95 | new Integration(), |
||
96 | new Integration\ExceptionContextIntegration(), |
||
97 | ]; |
||
98 | |||
99 | $integrationsToResolve = $this->configuration->getIntegrations(); |
||
100 | |||
101 | $enableDefaultTracingIntegrations = !isset($this->configuration->getTracing()['default_integrations']) || |
||
102 | (bool)$this->configuration->getTracing()['default_integrations']; |
||
103 | |||
104 | if ( |
||
105 | $enableDefaultTracingIntegrations |
||
106 | && $this->configuration->couldHavePerformanceTracingEnabled() |
||
107 | ) { |
||
108 | $integrationsToResolve = array_merge( |
||
109 | $integrationsToResolve, |
||
110 | self::DEFAULT_INTEGRATIONS |
||
111 | ); |
||
112 | } |
||
113 | /** @psalm-suppress MixedAssignment */ |
||
114 | foreach ($integrationsToResolve as $userIntegration) { |
||
115 | if ( |
||
116 | $userIntegration instanceof |
||
117 | SdkIntegration\IntegrationInterface |
||
118 | ) { |
||
119 | $integrations[] = $userIntegration; |
||
120 | } elseif (is_string($userIntegration)) { |
||
121 | /** @psalm-suppress MixedAssignment */ |
||
122 | $resolvedIntegration = $this->container->get($userIntegration); |
||
123 | |||
124 | if ( |
||
125 | !$resolvedIntegration instanceof |
||
126 | SdkIntegration\IntegrationInterface |
||
127 | ) { |
||
128 | if (is_array($resolvedIntegration)) { |
||
129 | $value = 'array'; |
||
130 | } elseif (is_object($resolvedIntegration)) { |
||
131 | $value = $resolvedIntegration::class; |
||
132 | } elseif (null === $resolvedIntegration) { |
||
133 | $value = 'null'; |
||
134 | } else { |
||
135 | $value = (string)$resolvedIntegration; |
||
136 | } |
||
137 | |||
138 | throw new RuntimeException( |
||
139 | sprintf( |
||
140 | 'Sentry integration must be an instance of `%s` got `%s`.', |
||
141 | SdkIntegration\IntegrationInterface::class, |
||
142 | $value |
||
143 | ) |
||
144 | ); |
||
145 | } |
||
146 | |||
147 | $integrations[] = $resolvedIntegration; |
||
148 | } else { |
||
149 | throw new RuntimeException( |
||
150 | sprintf( |
||
151 | 'Sentry integration must either be a valid container reference or an instance of `%s`.', |
||
152 | SdkIntegration\IntegrationInterface::class |
||
153 | ) |
||
154 | ); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | return $integrations; |
||
159 | } |
||
161 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: