Skip to content

Commit dd170e4

Browse files
committed
Use method_exists to check for option support
1 parent 23073a8 commit dd170e4

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ parameters:
66
ignoreErrors:
77
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
88
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
9+
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
10+
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
911
- '/Parameter \$.+ of method Sentry\\SentryBundle\\EventListener\\ErrorListener::onConsoleException\(\) has invalid typehint type Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
1012
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
1113
- '/Access to undefined constant Symfony\\Component\\Console\\ConsoleEvents::EXCEPTION./'

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,11 @@ private function isNotAValidCallback(): \Closure
180180

181181
private function classSerializersAreSupported(): bool
182182
{
183-
return $this->optionIsSupported('class_serializers', []);
183+
return method_exists(Options::class, 'getClassSerializers');
184184
}
185185

186186
private function maxRequestBodySizeIsSupported(): bool
187187
{
188-
return $this->optionIsSupported('max_request_body_size', 'none');
189-
}
190-
191-
private function optionIsSupported(string $name, $defaultValue): bool
192-
{
193-
try {
194-
new Options([$name => $defaultValue]);
195-
196-
return true;
197-
} catch (\Throwable $throwable) {
198-
return false;
199-
}
188+
return method_exists(Options::class, 'getMaxRequestBodySize');
200189
}
201190
}

test/BaseTestCase.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ abstract class BaseTestCase extends TestCase
99
{
1010
protected function classSerializersAreSupported(): bool
1111
{
12-
return $this->optionIsSupported('class_serializers', []);
12+
return method_exists(Options::class, 'getClassSerializers');
1313
}
1414

1515
protected function maxRequestBodySizeIsSupported(): bool
1616
{
17-
return $this->optionIsSupported('max_request_body_size', 'none');
17+
return method_exists(Options::class, 'getMaxRequestBodySize');
1818
}
1919

2020
protected function getSupportedOptionsCount(): int
@@ -31,15 +31,4 @@ protected function getSupportedOptionsCount(): int
3131

3232
return $count;
3333
}
34-
35-
private function optionIsSupported(string $name, $defaultValue): bool
36-
{
37-
try {
38-
new Options([$name => $defaultValue]);
39-
40-
return true;
41-
} catch (\Throwable $throwable) {
42-
return false;
43-
}
44-
}
4534
}

0 commit comments

Comments
 (0)