Skip to content

Commit 74b16b9

Browse files
committed
Refactor SentryExtension callable injection
1 parent 9f56167 commit 74b16b9

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/DependencyInjection/SentryExtension.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1010
use Symfony\Component\Config\FileLocator;
1111
use Symfony\Component\DependencyInjection\ContainerBuilder;
12+
use Symfony\Component\DependencyInjection\Definition;
1213
use Symfony\Component\DependencyInjection\Loader;
1314
use Symfony\Component\DependencyInjection\Reference;
1415
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -86,25 +87,27 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
8687
}
8788

8889
if (\array_key_exists('before_send', $processedOptions)) {
89-
$optionValue = $processedOptions['before_send'];
90-
if (is_string($optionValue) && 0 === strpos($optionValue, '@')) {
91-
$beforeSend = new Reference(substr($optionValue, 1));
92-
} else {
93-
$beforeSend = $optionValue;
94-
}
95-
96-
$options->addMethodCall('setBeforeSendCallback', [$beforeSend]);
90+
$this->mapCallableValue($options, 'setBeforeSendCallback', $processedOptions['before_send']);
9791
}
9892

9993
if (\array_key_exists('before_breadcrumb', $processedOptions)) {
100-
$optionValue = $processedOptions['before_breadcrumb'];
101-
if (is_string($optionValue) && 0 === strpos($optionValue, '@')) {
102-
$beforeSend = new Reference(substr($optionValue, 1));
103-
} else {
104-
$beforeSend = $optionValue;
105-
}
94+
$this->mapCallableValue($options, 'setBeforeBreadcrumbCallback', $processedOptions['before_breadcrumb']);
95+
}
96+
}
10697

107-
$options->addMethodCall('setBeforeBreadcrumbCallback', [$beforeSend]);
98+
/**
99+
* @param Definition $options
100+
* @param string $method
101+
* @param callable|string $optionValue
102+
*/
103+
private function mapCallableValue(Definition $options, string $method, $optionValue): void
104+
{
105+
if (is_string($optionValue) && 0 === strpos($optionValue, '@')) {
106+
$beforeSend = new Reference(substr($optionValue, 1));
107+
} else {
108+
$beforeSend = $optionValue;
108109
}
110+
111+
$options->addMethodCall($method, [$beforeSend]);
109112
}
110113
}

0 commit comments

Comments
 (0)