diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca077dcf..8cc888ab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,6 +5,24 @@ on: pull_request: jobs: + php-cs-fixer: + runs-on: ubuntu-latest + name: Coding Standards + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + + with: + php-version: 8.3 + coverage: none + tools: php-cs-fixer, cs2pr + + - name: Run PHP-CS-Fixer + run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr + test: runs-on: ubuntu-latest name: PHPUnit Tests diff --git a/.gitignore b/.gitignore index 18e0a276..c5158513 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor +.php-cs-fixer.cache composer.phar composer.lock phpunit.xml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..28302c82 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +$fileHeaderComment = <<<'EOF' +This file is part of the Symfony package. + +(c) Fabien Potencier + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PHP71Migration' => true, + '@PHPUnit75Migration:risky' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + 'protected_to_private' => false, + 'header_comment' => ['header' => $fileHeaderComment], + 'modernize_strpos' => false, + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']], + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in([__DIR__]) + ->append([__FILE__]) + ) +; diff --git a/DependencyInjection/Compiler/AddProcessorsPass.php b/DependencyInjection/Compiler/AddProcessorsPass.php index 68d3adf1..cc99b67d 100644 --- a/DependencyInjection/Compiler/AddProcessorsPass.php +++ b/DependencyInjection/Compiler/AddProcessorsPass.php @@ -34,24 +34,24 @@ public function process(ContainerBuilder $container) foreach ($container->findTaggedServiceIds('monolog.processor') as $id => $tags) { foreach ($tags as $tag) { if (!empty($tag['channel']) && !empty($tag['handler'])) { - throw new \InvalidArgumentException(sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id)); + throw new \InvalidArgumentException(\sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id)); } if (!empty($tag['handler'])) { - $definition = $container->findDefinition(sprintf('monolog.handler.%s', $tag['handler'])); + $definition = $container->findDefinition(\sprintf('monolog.handler.%s', $tag['handler'])); $parentDef = $definition; while (!$parentDef->getClass() && $parentDef instanceof ChildDefinition) { $parentDef = $container->findDefinition($parentDef->getParent()); } $class = $container->getParameterBag()->resolveValue($parentDef->getClass()); if (!method_exists($class, 'pushProcessor')) { - throw new \InvalidArgumentException(sprintf('The "%s" handler does not accept processors', $tag['handler'])); + throw new \InvalidArgumentException(\sprintf('The "%s" handler does not accept processors', $tag['handler'])); } } elseif (!empty($tag['channel'])) { if ('app' === $tag['channel']) { $definition = $container->getDefinition('monolog.logger'); } else { - $definition = $container->getDefinition(sprintf('monolog.logger.%s', $tag['channel'])); + $definition = $container->getDefinition(\sprintf('monolog.logger.%s', $tag['channel'])); } } else { $definition = $container->getDefinition('monolog.logger_prototype'); diff --git a/DependencyInjection/Compiler/AddSwiftMailerTransportPass.php b/DependencyInjection/Compiler/AddSwiftMailerTransportPass.php index de0998f7..2669bdd9 100644 --- a/DependencyInjection/Compiler/AddSwiftMailerTransportPass.php +++ b/DependencyInjection/Compiler/AddSwiftMailerTransportPass.php @@ -11,8 +11,8 @@ namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; /** @@ -25,9 +25,6 @@ */ class AddSwiftMailerTransportPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ public function process(ContainerBuilder $container) { $handlers = $container->getParameter('monolog.swift_mailer.handlers'); diff --git a/DependencyInjection/Compiler/DebugHandlerPass.php b/DependencyInjection/Compiler/DebugHandlerPass.php index 3598698a..b076f162 100644 --- a/DependencyInjection/Compiler/DebugHandlerPass.php +++ b/DependencyInjection/Compiler/DebugHandlerPass.php @@ -11,11 +11,11 @@ namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Monolog\Logger; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Monolog\Logger; +use Symfony\Component\DependencyInjection\Reference; /** * Adds the DebugHandler when the profiler is enabled and kernel.debug is true. @@ -31,7 +31,7 @@ class DebugHandlerPass implements CompilerPassInterface public function __construct(LoggerChannelPass $channelPass) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', E_USER_DEPRECATED); + @trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', \E_USER_DEPRECATED); $this->channelPass = $channelPass; } @@ -51,7 +51,7 @@ public function process(ContainerBuilder $container) foreach ($this->channelPass->getChannels() as $channel) { $container - ->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel) + ->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel) ->addMethodCall('pushHandler', [new Reference('monolog.handler.debug')]); } } diff --git a/DependencyInjection/Compiler/FixEmptyLoggerPass.php b/DependencyInjection/Compiler/FixEmptyLoggerPass.php index 13bf1343..9d9599bc 100644 --- a/DependencyInjection/Compiler/FixEmptyLoggerPass.php +++ b/DependencyInjection/Compiler/FixEmptyLoggerPass.php @@ -44,7 +44,7 @@ public function process(ContainerBuilder $container) { $container->register('monolog.handler.null_internal', 'Monolog\Handler\NullHandler'); foreach ($this->channelPass->getChannels() as $channel) { - $def = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel); + $def = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel); foreach ($def->getMethodCalls() as $method) { if ('pushHandler' === $method[0]) { continue 2; diff --git a/DependencyInjection/Compiler/LoggerChannelPass.php b/DependencyInjection/Compiler/LoggerChannelPass.php index 4f4da6c2..4c7b147c 100644 --- a/DependencyInjection/Compiler/LoggerChannelPass.php +++ b/DependencyInjection/Compiler/LoggerChannelPass.php @@ -30,9 +30,6 @@ class LoggerChannelPass implements CompilerPassInterface { protected $channels = ['app']; - /** - * {@inheritDoc} - */ public function process(ContainerBuilder $container) { if (!$container->hasDefinition('monolog.logger')) { @@ -49,7 +46,7 @@ public function process(ContainerBuilder $container) $resolvedChannel = $container->getParameterBag()->resolveValue($tag['channel']); $definition = $container->getDefinition($id); - $loggerId = sprintf('monolog.logger.%s', $resolvedChannel); + $loggerId = \sprintf('monolog.logger.%s', $resolvedChannel); $this->createLogger($resolvedChannel, $loggerId, $container); foreach ($definition->getArguments() as $index => $argument) { @@ -84,10 +81,10 @@ public function process(ContainerBuilder $container) // create additional channels foreach ($container->getParameter('monolog.additional_channels') as $chan) { - if ($chan === 'app') { + if ('app' === $chan) { continue; } - $loggerId = sprintf('monolog.logger.%s', $chan); + $loggerId = \sprintf('monolog.logger.%s', $chan); $this->createLogger($chan, $loggerId, $container); $container->getDefinition($loggerId)->setPublic(true); } @@ -98,7 +95,7 @@ public function process(ContainerBuilder $container) foreach ($handlersToChannels as $handler => $channels) { foreach ($this->processChannels($channels) as $channel) { try { - $logger = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel); + $logger = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel); } catch (InvalidArgumentException $e) { $msg = 'Monolog configuration error: The logging channel "'.$channel.'" assigned to the "'.substr($handler, 16).'" handler does not exist.'; throw new \InvalidArgumentException($msg, 0, $e); @@ -133,20 +130,20 @@ protected function processChannels(?array $configuration) } /** - * Create new logger from the monolog.logger_prototype + * Create new logger from the monolog.logger_prototype. * * @return void */ protected function createLogger(string $channel, string $loggerId, ContainerBuilder $container) { - if (!in_array($channel, $this->channels)) { + if (!\in_array($channel, $this->channels)) { $logger = new ChildDefinition('monolog.logger_prototype'); $logger->replaceArgument(0, $channel); $container->setDefinition($loggerId, $logger); $this->channels[] = $channel; } - $parameterName = $channel . 'Logger'; + $parameterName = $channel.'Logger'; $container->registerAliasForArgument($loggerId, LoggerInterface::class, $parameterName); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index eea9347f..255eba47 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -12,14 +12,13 @@ namespace Symfony\Bundle\MonologBundle\DependencyInjection; use Monolog\Logger; -use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; /** - * This class contains the configuration information for the bundle + * This class contains the configuration information for the bundle. * * This information is solely responsible for how the different configuration * sections are normalized, and merged. @@ -422,7 +421,7 @@ public function getConfigTreeBuilder(): TreeBuilder 'custom' => [ 'type' => 'service', 'id' => 'my_handler', - ] + ], ]); $handlerNode = $handlers @@ -470,7 +469,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->beforeNormalization() ->ifString() ->then(function ($v) { - if (substr($v, 0, 1) === '0') { + if ('0' === substr($v, 0, 1)) { return octdec($v); } @@ -479,10 +478,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->booleanNode('use_locking')->defaultFalse()->end() // stream and rotating - ->scalarNode('filename_format')->defaultValue('{filename}-{date}')->end() //rotating - ->scalarNode('date_format')->defaultValue('Y-m-d')->end() //rotating + ->scalarNode('filename_format')->defaultValue('{filename}-{date}')->end() // rotating + ->scalarNode('date_format')->defaultValue('Y-m-d')->end() // rotating ->scalarNode('ident')->defaultFalse()->end() // syslog and syslogudp - ->scalarNode('logopts')->defaultValue(LOG_PID)->end() // syslog + ->scalarNode('logopts')->defaultValue(\LOG_PID)->end() // syslog ->scalarNode('facility')->defaultValue('user')->end() // syslog ->scalarNode('max_files')->defaultValue(0)->end() // rotating ->scalarNode('action_level')->defaultValue('WARNING')->end() // fingers_crossed @@ -510,7 +509,7 @@ public function getConfigTreeBuilder(): TreeBuilder * */ - if (is_array($value)) { + if (\is_array($value)) { return isset($value['code']) ? $value : ['code' => key($value), 'urls' => current($value)]; } @@ -532,7 +531,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->prototype('scalar')->end() ->end() ->scalarNode('min_level')->defaultValue('DEBUG')->end() // filter - ->scalarNode('max_level')->defaultValue('EMERGENCY')->end() //filter + ->scalarNode('max_level')->defaultValue('EMERGENCY')->end() // filter ->scalarNode('buffer_size')->defaultValue(0)->end() // fingers_crossed and buffer ->booleanNode('flush_on_overflow')->defaultFalse()->end() // buffer ->scalarNode('handler')->end() // fingers_crossed and buffer @@ -559,7 +558,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('user') // pushover ->validate() ->ifTrue(function ($v) { - return !is_string($v) && !is_array($v); + return !\is_string($v) && !\is_array($v); }) ->thenInvalid('User must be a string or an array.') ->end() @@ -612,7 +611,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->setDeprecated('symfony/monolog-bundle', 3.7, '"%path%.%node%" is deprecated, use "%path%.console_formatter_options" instead.') ->validate() ->ifTrue(function ($v) { - return !is_array($v); + return !\is_array($v); }) ->thenInvalid('The console_formater_options must be an array.') ->end() @@ -620,7 +619,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('console_formatter_options') ->defaultValue([]) ->validate() - ->ifTrue(static function ($v) { return !is_array($v); }) + ->ifTrue(static function ($v) { return !\is_array($v); }) ->thenInvalid('The console_formatter_options must be an array.') ->end() ->end() @@ -648,7 +647,11 @@ public function getConfigTreeBuilder(): TreeBuilder }) ->end() ->validate() - ->always(static function ($v) { unset($v['console_formater_options']); return $v; }) + ->always(static function ($v) { + unset($v['console_formater_options']); + + return $v; + }) ->end() ->validate() ->ifTrue(function ($v) { return 'service' === $v['type'] && !empty($v['formatter']); }) @@ -675,11 +678,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->thenInvalid('You can only use excluded_http_codes/excluded_404s with a FingersCrossedHandler definition') ->end() ->validate() - ->ifTrue(function ($v) { return 'filter' === $v['type'] && "DEBUG" !== $v['min_level'] && !empty($v['accepted_levels']); }) + ->ifTrue(function ($v) { return 'filter' === $v['type'] && 'DEBUG' !== $v['min_level'] && !empty($v['accepted_levels']); }) ->thenInvalid('You can not use min_level together with accepted_levels in a FilterHandler') ->end() ->validate() - ->ifTrue(function ($v) { return 'filter' === $v['type'] && "EMERGENCY" !== $v['max_level'] && !empty($v['accepted_levels']); }) + ->ifTrue(function ($v) { return 'filter' === $v['type'] && 'EMERGENCY' !== $v['max_level'] && !empty($v['accepted_levels']); }) ->thenInvalid('You can not use max_level together with accepted_levels in a FilterHandler') ->end() ->validate() @@ -711,11 +714,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->thenInvalid('The token and user have to be specified to use a PushoverHandler') ->end() ->validate() - ->ifTrue(function ($v) { return 'raven' === $v['type'] && !array_key_exists('dsn', $v) && null === $v['client_id']; }) + ->ifTrue(function ($v) { return 'raven' === $v['type'] && !\array_key_exists('dsn', $v) && null === $v['client_id']; }) ->thenInvalid('The DSN has to be specified to use a RavenHandler') ->end() ->validate() - ->ifTrue(function ($v) { return 'sentry' === $v['type'] && !array_key_exists('dsn', $v) && null === $v['hub_id'] && null === $v['client_id']; }) + ->ifTrue(function ($v) { return 'sentry' === $v['type'] && !\array_key_exists('dsn', $v) && null === $v['hub_id'] && null === $v['client_id']; }) ->thenInvalid('The DSN has to be specified to use Sentry\'s handler') ->end() ->validate() @@ -727,11 +730,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->thenInvalid('The token and room have to be specified to use a HipChatHandler') ->end() ->validate() - ->ifTrue(function ($v) { return 'hipchat' === $v['type'] && !in_array($v['message_format'], ['text', 'html']); }) + ->ifTrue(function ($v) { return 'hipchat' === $v['type'] && !\in_array($v['message_format'], ['text', 'html']); }) ->thenInvalid('The message_format has to be "text" or "html" in a HipChatHandler') ->end() ->validate() - ->ifTrue(function ($v) { return 'hipchat' === $v['type'] && null !== $v['api_version'] && !in_array($v['api_version'], ['v1', 'v2'], true); }) + ->ifTrue(function ($v) { return 'hipchat' === $v['type'] && null !== $v['api_version'] && !\in_array($v['api_version'], ['v1', 'v2'], true); }) ->thenInvalid('The api_version has to be "v1" or "v2" in a HipChatHandler') ->end() ->validate() @@ -761,9 +764,9 @@ public function getConfigTreeBuilder(): TreeBuilder ->validate() ->ifTrue(function ($v) { return 'loggly' === $v['type'] && !empty($v['tags']); }) ->then(function ($v) { - $invalidTags = preg_grep('/^[a-z0-9][a-z0-9\.\-_]*$/i', $v['tags'], PREG_GREP_INVERT); + $invalidTags = preg_grep('/^[a-z0-9][a-z0-9\.\-_]*$/i', $v['tags'], \PREG_GREP_INVERT); if (!empty($invalidTags)) { - throw new InvalidConfigurationException(sprintf('The following Loggly tags are invalid: %s.', implode(', ', $invalidTags))); + throw new InvalidConfigurationException(\sprintf('The following Loggly tags are invalid: %s.', implode(', ', $invalidTags))); } return $v; @@ -1022,7 +1025,7 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode) $verbosities = ['VERBOSITY_QUIET', 'VERBOSITY_NORMAL', 'VERBOSITY_VERBOSE', 'VERBOSITY_VERY_VERBOSE', 'VERBOSITY_DEBUG']; // allow numeric indexed array with ascendning verbosity and lowercase names of the constants foreach ($v as $verbosity => $level) { - if (is_int($verbosity) && isset($verbosities[$verbosity])) { + if (\is_int($verbosity) && isset($verbosities[$verbosity])) { $map[$verbosities[$verbosity]] = strtoupper($level); } else { $map[strtoupper($verbosity)] = strtoupper($level); @@ -1045,11 +1048,8 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode) foreach ($v as $verbosity => $level) { $verbosityConstant = 'Symfony\Component\Console\Output\OutputInterface::'.$verbosity; - if (!defined($verbosityConstant)) { - throw new InvalidConfigurationException(sprintf( - 'The configured verbosity "%s" is invalid as it is not defined in Symfony\Component\Console\Output\OutputInterface.', - $verbosity - )); + if (!\defined($verbosityConstant)) { + throw new InvalidConfigurationException(\sprintf('The configured verbosity "%s" is invalid as it is not defined in Symfony\Component\Console\Output\OutputInterface.', $verbosity)); } try { @@ -1059,13 +1059,10 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode) $level = Logger::toMonologLevel(is_numeric($level) ? (int) $level : $level); } } catch (\Psr\Log\InvalidArgumentException $e) { - throw new InvalidConfigurationException(sprintf( - 'The configured minimum log level "%s" for verbosity "%s" is invalid as it is not defined in Monolog\Logger.', - $level, $verbosity - )); + throw new InvalidConfigurationException(\sprintf('The configured minimum log level "%s" for verbosity "%s" is invalid as it is not defined in Monolog\Logger.', $level, $verbosity)); } - $map[constant($verbosityConstant)] = $level; + $map[\constant($verbosityConstant)] = $level; } return $map; @@ -1088,7 +1085,7 @@ private function addChannelsSection(ArrayNodeDefinition $handerNode) ->then(function ($v) { return ['elements' => [$v]]; }) ->end() ->beforeNormalization() - ->ifTrue(function ($v) { return is_array($v) && is_numeric(key($v)); }) + ->ifTrue(function ($v) { return \is_array($v) && is_numeric(key($v)); }) ->then(function ($v) { return ['elements' => $v]; }) ->end() ->validate() @@ -1119,7 +1116,7 @@ private function addChannelsSection(ArrayNodeDefinition $handerNode) } } - if (!count($elements)) { + if (!\count($elements)) { return null; } diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index 0e64f088..1d47a984 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -20,11 +20,10 @@ use Monolog\Processor\PsrLogMessageProcessor; use Monolog\ResettableInterface; use Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy; +use Symfony\Bridge\Monolog\Logger as LegacyLogger; use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; use Symfony\Bridge\Monolog\Processor\TokenProcessor; use Symfony\Bridge\Monolog\Processor\WebProcessor; -use Symfony\Bridge\Monolog\Logger as LegacyLogger; -use Symfony\Bundle\FullStack; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -61,7 +60,6 @@ public function load(array $configs, ContainerBuilder $container) $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); - if (isset($config['handlers'])) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('monolog.xml'); @@ -96,14 +94,14 @@ public function load(array $configs, ContainerBuilder $container) $handlersToChannels = []; foreach ($sortedHandlers as $handler) { - if (!in_array($handler['id'], $this->nestedHandlers)) { + if (!\in_array($handler['id'], $this->nestedHandlers)) { $handlersToChannels[$handler['id']] = $handler['channels']; } } $container->setParameter('monolog.handlers_to_channels', $handlersToChannels); } - $container->setParameter('monolog.additional_channels', isset($config['channels']) ? $config['channels'] : []); + $container->setParameter('monolog.additional_channels', $config['channels'] ?? []); if (interface_exists(ProcessorInterface::class)) { $container->registerForAutoconfiguration(ProcessorInterface::class) @@ -130,7 +128,7 @@ public function load(array $configs, ContainerBuilder $container) $tagAttributes = get_object_vars($attribute); if ($reflector instanceof \ReflectionMethod) { if (isset($tagAttributes['method'])) { - throw new \LogicException(sprintf('AsMonologProcessor attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); + throw new \LogicException(\sprintf('AsMonologProcessor attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); } $tagAttributes['method'] = $reflector->getName(); @@ -189,736 +187,736 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler } switch ($handler['type']) { - case 'stream': - $definition->setArguments([ - $handler['path'], - $handler['level'], - $handler['bubble'], - $handler['file_permission'], - $handler['use_locking'], - ]); - break; - - case 'console': - $definition->setArguments([ - null, - $handler['bubble'], - isset($handler['verbosity_levels']) ? $handler['verbosity_levels'] : [], - $handler['console_formatter_options'] - ]); - $definition->addTag('kernel.event_subscriber'); - break; - - case 'chromephp': - case 'firephp': - $definition->setArguments([ - $handler['level'], - $handler['bubble'], - ]); - $definition->addTag('kernel.event_listener', ['event' => 'kernel.response', 'method' => 'onKernelResponse']); - break; - - case 'gelf': - if (isset($handler['publisher']['id'])) { - $publisher = new Reference($handler['publisher']['id']); - } elseif (class_exists('Gelf\Transport\UdpTransport')) { - $transport = new Definition("Gelf\Transport\UdpTransport", [ - $handler['publisher']['hostname'], - $handler['publisher']['port'], - $handler['publisher']['chunk_size'], + case 'stream': + $definition->setArguments([ + $handler['path'], + $handler['level'], + $handler['bubble'], + $handler['file_permission'], + $handler['use_locking'], ]); - $transport->setPublic(false); - - $publisher = new Definition('Gelf\Publisher', []); - $publisher->addMethodCall('addTransport', [$transport]); - $publisher->setPublic(false); - } elseif (class_exists('Gelf\MessagePublisher')) { - $publisher = new Definition('Gelf\MessagePublisher', [ - $handler['publisher']['hostname'], - $handler['publisher']['port'], - $handler['publisher']['chunk_size'], + break; + + case 'console': + $definition->setArguments([ + null, + $handler['bubble'], + $handler['verbosity_levels'] ?? [], + $handler['console_formatter_options'], ]); + $definition->addTag('kernel.event_subscriber'); + break; + + case 'chromephp': + case 'firephp': + $definition->setArguments([ + $handler['level'], + $handler['bubble'], + ]); + $definition->addTag('kernel.event_listener', ['event' => 'kernel.response', 'method' => 'onKernelResponse']); + break; + + case 'gelf': + if (isset($handler['publisher']['id'])) { + $publisher = new Reference($handler['publisher']['id']); + } elseif (class_exists('Gelf\Transport\UdpTransport')) { + $transport = new Definition("Gelf\Transport\UdpTransport", [ + $handler['publisher']['hostname'], + $handler['publisher']['port'], + $handler['publisher']['chunk_size'], + ]); + $transport->setPublic(false); + + $publisher = new Definition('Gelf\Publisher', []); + $publisher->addMethodCall('addTransport', [$transport]); + $publisher->setPublic(false); + } elseif (class_exists('Gelf\MessagePublisher')) { + $publisher = new Definition('Gelf\MessagePublisher', [ + $handler['publisher']['hostname'], + $handler['publisher']['port'], + $handler['publisher']['chunk_size'], + ]); + + $publisher->setPublic(false); + } else { + throw new \RuntimeException('The gelf handler requires the graylog2/gelf-php package to be installed'); + } - $publisher->setPublic(false); - } else { - throw new \RuntimeException('The gelf handler requires the graylog2/gelf-php package to be installed'); - } + $definition->setArguments([ + $publisher, + $handler['level'], + $handler['bubble'], + ]); + break; - $definition->setArguments([ - $publisher, - $handler['level'], - $handler['bubble'], - ]); - break; + case 'mongo': + if (isset($handler['mongo']['id'])) { + $client = new Reference($handler['mongo']['id']); + } else { + $server = 'mongodb://'; - case 'mongo': - if (isset($handler['mongo']['id'])) { - $client = new Reference($handler['mongo']['id']); - } else { - $server = 'mongodb://'; + if (isset($handler['mongo']['user'])) { + $server .= $handler['mongo']['user'].':'.$handler['mongo']['pass'].'@'; + } - if (isset($handler['mongo']['user'])) { - $server .= $handler['mongo']['user'].':'.$handler['mongo']['pass'].'@'; - } + $server .= $handler['mongo']['host'].':'.$handler['mongo']['port']; - $server .= $handler['mongo']['host'].':'.$handler['mongo']['port']; + $client = new Definition('MongoDB\Client', [ + $server, + ]); - $client = new Definition('MongoDB\Client', [ - $server, + $client->setPublic(false); + } + + $definition->setArguments([ + $client, + $handler['mongo']['database'], + $handler['mongo']['collection'], + $handler['level'], + $handler['bubble'], ]); + break; - $client->setPublic(false); - } + case 'elasticsearch': + @trigger_error('The "elasticsearch" handler type is deprecated in MonologBundle since version 3.8.0, use the "elastica" type instead, or switch to the official Elastic client using the "elastic_search" type.', \E_USER_DEPRECATED); + // no break - $definition->setArguments([ - $client, - $handler['mongo']['database'], - $handler['mongo']['collection'], - $handler['level'], - $handler['bubble'], - ]); - break; - - case 'elasticsearch': - @trigger_error('The "elasticsearch" handler type is deprecated in MonologBundle since version 3.8.0, use the "elastica" type instead, or switch to the official Elastic client using the "elastic_search" type.', E_USER_DEPRECATED); - // no break - - case 'elastica': - case 'elastic_search': - if (isset($handler['elasticsearch']['id'])) { - $client = new Reference($handler['elasticsearch']['id']); - } else { - if ($handler['type'] === 'elastic_search') { - // v8 has a new Elastic\ prefix - $client = new Definition(class_exists('Elastic\Elasticsearch\Client') ? 'Elastic\Elasticsearch\Client' : 'Elasticsearch\Client'); - $factory = class_exists('Elastic\Elasticsearch\ClientBuilder') ? 'Elastic\Elasticsearch\ClientBuilder' : 'Elasticsearch\ClientBuilder'; - $client->setFactory([$factory, 'fromConfig']); - $clientArguments = [ - 'host' => $handler['elasticsearch']['host'], - ]; - - if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) { - $clientArguments['basicAuthentication'] = [$handler['elasticsearch']['user'], $handler['elasticsearch']['password']]; - } + case 'elastica': + case 'elastic_search': + if (isset($handler['elasticsearch']['id'])) { + $client = new Reference($handler['elasticsearch']['id']); } else { - $client = new Definition('Elastica\Client'); + if ('elastic_search' === $handler['type']) { + // v8 has a new Elastic\ prefix + $client = new Definition(class_exists('Elastic\Elasticsearch\Client') ? 'Elastic\Elasticsearch\Client' : 'Elasticsearch\Client'); + $factory = class_exists('Elastic\Elasticsearch\ClientBuilder') ? 'Elastic\Elasticsearch\ClientBuilder' : 'Elasticsearch\ClientBuilder'; + $client->setFactory([$factory, 'fromConfig']); + $clientArguments = [ + 'host' => $handler['elasticsearch']['host'], + ]; - $clientArguments = [ - 'host' => $handler['elasticsearch']['host'], - 'port' => $handler['elasticsearch']['port'], - 'transport' => $handler['elasticsearch']['transport'], - ]; + if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) { + $clientArguments['basicAuthentication'] = [$handler['elasticsearch']['user'], $handler['elasticsearch']['password']]; + } + } else { + $client = new Definition('Elastica\Client'); - if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) { - $clientArguments['headers'] = [ - 'Authorization' => 'Basic ' . base64_encode($handler['elasticsearch']['user'] . ':' . $handler['elasticsearch']['password']) + $clientArguments = [ + 'host' => $handler['elasticsearch']['host'], + 'port' => $handler['elasticsearch']['port'], + 'transport' => $handler['elasticsearch']['transport'], ]; + + if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) { + $clientArguments['headers'] = [ + 'Authorization' => 'Basic '.base64_encode($handler['elasticsearch']['user'].':'.$handler['elasticsearch']['password']), + ]; + } } + + $client->setArguments([ + $clientArguments, + ]); + + $client->setPublic(false); } - $client->setArguments([ - $clientArguments + // elastica handler definition + $definition->setArguments([ + $client, + [ + 'index' => $handler['index'], + 'type' => $handler['document_type'], + 'ignore_error' => $handler['ignore_error'], + ], + $handler['level'], + $handler['bubble'], ]); + break; - $client->setPublic(false); - } + case 'telegram': + if (!class_exists('Monolog\Handler\TelegramBotHandler')) { + throw new \RuntimeException('The TelegramBotHandler is not available. Please update "monolog/monolog" to 2.2.0'); + } - // elastica handler definition - $definition->setArguments([ - $client, - [ - 'index' => $handler['index'], - 'type' => $handler['document_type'], - 'ignore_error' => $handler['ignore_error'] - ], - $handler['level'], - $handler['bubble'], - ]); - break; + $definition->setArguments([ + $handler['token'], + $handler['channel'], + $handler['level'], + $handler['bubble'], + $handler['parse_mode'], + $handler['disable_webpage_preview'], + $handler['disable_notification'], + $handler['split_long_messages'], + $handler['delay_between_messages'], + ]); + break; + + case 'redis': + case 'predis': + if (isset($handler['redis']['id'])) { + $clientId = $handler['redis']['id']; + } elseif ('redis' === $handler['type']) { + if (!class_exists(\Redis::class)) { + throw new \RuntimeException('The \Redis class is not available.'); + } - case 'telegram': - if (!class_exists('Monolog\Handler\TelegramBotHandler')) { - throw new \RuntimeException('The TelegramBotHandler is not available. Please update "monolog/monolog" to 2.2.0'); - } + $client = new Definition(\Redis::class); + $client->addMethodCall('connect', [$handler['redis']['host'], $handler['redis']['port']]); + $client->addMethodCall('auth', [$handler['redis']['password']]); + $client->addMethodCall('select', [$handler['redis']['database']]); + $client->setPublic(false); + $clientId = uniqid('monolog.redis.client.', true); + $container->setDefinition($clientId, $client); + } else { + if (!class_exists(\Predis\Client::class)) { + throw new \RuntimeException('The \Predis\Client class is not available.'); + } - $definition->setArguments([ - $handler['token'], - $handler['channel'], - $handler['level'], - $handler['bubble'], - $handler['parse_mode'], - $handler['disable_webpage_preview'], - $handler['disable_notification'], - $handler['split_long_messages'], - $handler['delay_between_messages'], - ]); - break; - - case 'redis': - case 'predis': - if (isset($handler['redis']['id'])) { - $clientId = $handler['redis']['id']; - } elseif ('redis' === $handler['type']) { - if (!class_exists(\Redis::class)) { - throw new \RuntimeException('The \Redis class is not available.'); - } + $client = new Definition(\Predis\Client::class); + $client->setArguments([ + $handler['redis']['host'], + ]); + $client->setPublic(false); - $client = new Definition(\Redis::class); - $client->addMethodCall('connect', [$handler['redis']['host'], $handler['redis']['port']]); - $client->addMethodCall('auth', [$handler['redis']['password']]); - $client->addMethodCall('select', [$handler['redis']['database']]); - $client->setPublic(false); - $clientId = uniqid('monolog.redis.client.', true); - $container->setDefinition($clientId, $client); - } else { - if (!class_exists(\Predis\Client::class)) { - throw new \RuntimeException('The \Predis\Client class is not available.'); + $clientId = uniqid('monolog.predis.client.', true); + $container->setDefinition($clientId, $client); } - - $client = new Definition(\Predis\Client::class); - $client->setArguments([ - $handler['redis']['host'], + $definition->setArguments([ + new Reference($clientId), + $handler['redis']['key_name'], + $handler['level'], + $handler['bubble'], ]); - $client->setPublic(false); - - $clientId = uniqid('monolog.predis.client.', true); - $container->setDefinition($clientId, $client); - } - $definition->setArguments([ - new Reference($clientId), - $handler['redis']['key_name'], - $handler['level'], - $handler['bubble'], - ]); - break; - - case 'rotating_file': - $definition->setArguments([ - $handler['path'], - $handler['max_files'], - $handler['level'], - $handler['bubble'], - $handler['file_permission'], - $handler['use_locking'], - ]); - $definition->addMethodCall('setFilenameFormat', [ - $handler['filename_format'], - $handler['date_format'], - ]); - break; + break; + + case 'rotating_file': + $definition->setArguments([ + $handler['path'], + $handler['max_files'], + $handler['level'], + $handler['bubble'], + $handler['file_permission'], + $handler['use_locking'], + ]); + $definition->addMethodCall('setFilenameFormat', [ + $handler['filename_format'], + $handler['date_format'], + ]); + break; - case 'fingers_crossed': - $nestedHandlerId = $this->getHandlerId($handler['handler']); - $this->markNestedHandler($nestedHandlerId); + case 'fingers_crossed': + $nestedHandlerId = $this->getHandlerId($handler['handler']); + $this->markNestedHandler($nestedHandlerId); - $activation = $handler['action_level']; - if (class_exists(SwitchUserTokenProcessor::class)) { - $activation = new Definition(ErrorLevelActivationStrategy::class, [$activation]); - } + $activation = $handler['action_level']; + if (class_exists(SwitchUserTokenProcessor::class)) { + $activation = new Definition(ErrorLevelActivationStrategy::class, [$activation]); + } - if (isset($handler['activation_strategy'])) { - $activation = new Reference($handler['activation_strategy']); - } elseif (!empty($handler['excluded_404s'])) { - if (class_exists(HttpCodeActivationStrategy::class)) { - @trigger_error('The "excluded_404s" option is deprecated in MonologBundle since version 3.4.0, you should rely on the "excluded_http_codes" option instead.', E_USER_DEPRECATED); + if (isset($handler['activation_strategy'])) { + $activation = new Reference($handler['activation_strategy']); + } elseif (!empty($handler['excluded_404s'])) { + if (class_exists(HttpCodeActivationStrategy::class)) { + @trigger_error('The "excluded_404s" option is deprecated in MonologBundle since version 3.4.0, you should rely on the "excluded_http_codes" option instead.', \E_USER_DEPRECATED); + } + $activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy', [ + new Reference('request_stack'), + $handler['excluded_404s'], + $activation, + ]); + $container->setDefinition($handlerId.'.not_found_strategy', $activationDef); + $activation = new Reference($handlerId.'.not_found_strategy'); + } elseif (!empty($handler['excluded_http_codes'])) { + $activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy', [ + new Reference('request_stack'), + $handler['excluded_http_codes'], + $activation, + ]); + $container->setDefinition($handlerId.'.http_code_strategy', $activationDef); + $activation = new Reference($handlerId.'.http_code_strategy'); } - $activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy', [ - new Reference('request_stack'), - $handler['excluded_404s'], - $activation + + $definition->setArguments([ + new Reference($nestedHandlerId), + $activation, + $handler['buffer_size'], + $handler['bubble'], + $handler['stop_buffering'], + $handler['passthru_level'], ]); - $container->setDefinition($handlerId.'.not_found_strategy', $activationDef); - $activation = new Reference($handlerId.'.not_found_strategy'); - } elseif (!empty($handler['excluded_http_codes'])) { - $activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy', [ - new Reference('request_stack'), - $handler['excluded_http_codes'], - $activation + break; + + case 'filter': + $nestedHandlerId = $this->getHandlerId($handler['handler']); + $this->markNestedHandler($nestedHandlerId); + $minLevelOrList = !empty($handler['accepted_levels']) ? $handler['accepted_levels'] : $handler['min_level']; + + $definition->setArguments([ + new Reference($nestedHandlerId), + $minLevelOrList, + $handler['max_level'], + $handler['bubble'], ]); - $container->setDefinition($handlerId.'.http_code_strategy', $activationDef); - $activation = new Reference($handlerId.'.http_code_strategy'); - } + break; - $definition->setArguments([ - new Reference($nestedHandlerId), - $activation, - $handler['buffer_size'], - $handler['bubble'], - $handler['stop_buffering'], - $handler['passthru_level'], - ]); - break; - - case 'filter': - $nestedHandlerId = $this->getHandlerId($handler['handler']); - $this->markNestedHandler($nestedHandlerId); - $minLevelOrList = !empty($handler['accepted_levels']) ? $handler['accepted_levels'] : $handler['min_level']; - - $definition->setArguments([ - new Reference($nestedHandlerId), - $minLevelOrList, - $handler['max_level'], - $handler['bubble'], - ]); - break; - - case 'buffer': - $nestedHandlerId = $this->getHandlerId($handler['handler']); - $this->markNestedHandler($nestedHandlerId); - - $definition->setArguments([ - new Reference($nestedHandlerId), - $handler['buffer_size'], - $handler['level'], - $handler['bubble'], - $handler['flush_on_overflow'], - ]); - break; - - case 'deduplication': - $nestedHandlerId = $this->getHandlerId($handler['handler']); - $this->markNestedHandler($nestedHandlerId); - $defaultStore = '%kernel.cache_dir%/monolog_dedup_'.sha1($handlerId); - - $definition->setArguments([ - new Reference($nestedHandlerId), - isset($handler['store']) ? $handler['store'] : $defaultStore, - $handler['deduplication_level'], - $handler['time'], - $handler['bubble'], - ]); - break; - - case 'group': - case 'whatfailuregroup': - case 'fallbackgroup': - $references = []; - foreach ($handler['members'] as $nestedHandler) { - $nestedHandlerId = $this->getHandlerId($nestedHandler); + case 'buffer': + $nestedHandlerId = $this->getHandlerId($handler['handler']); $this->markNestedHandler($nestedHandlerId); - $references[] = new Reference($nestedHandlerId); - } - $definition->setArguments([ - $references, - $handler['bubble'], - ]); - break; - - case 'syslog': - $definition->setArguments([ - $handler['ident'], - $handler['facility'], - $handler['level'], - $handler['bubble'], - $handler['logopts'], - ]); - break; - - case 'syslogudp': - $definition->setArguments([ - $handler['host'], - $handler['port'], - $handler['facility'], - $handler['level'], - $handler['bubble'], - ]); - if ($handler['ident']) { - $definition->addArgument($handler['ident']); - } - break; + $definition->setArguments([ + new Reference($nestedHandlerId), + $handler['buffer_size'], + $handler['level'], + $handler['bubble'], + $handler['flush_on_overflow'], + ]); + break; - case 'swift_mailer': - $mailer = $handler['mailer'] ?: 'mailer'; - if (isset($handler['email_prototype'])) { - if (!empty($handler['email_prototype']['method'])) { - $prototype = [new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']]; + case 'deduplication': + $nestedHandlerId = $this->getHandlerId($handler['handler']); + $this->markNestedHandler($nestedHandlerId); + $defaultStore = '%kernel.cache_dir%/monolog_dedup_'.sha1($handlerId); + + $definition->setArguments([ + new Reference($nestedHandlerId), + $handler['store'] ?? $defaultStore, + $handler['deduplication_level'], + $handler['time'], + $handler['bubble'], + ]); + break; + + case 'group': + case 'whatfailuregroup': + case 'fallbackgroup': + $references = []; + foreach ($handler['members'] as $nestedHandler) { + $nestedHandlerId = $this->getHandlerId($nestedHandler); + $this->markNestedHandler($nestedHandlerId); + $references[] = new Reference($nestedHandlerId); + } + + $definition->setArguments([ + $references, + $handler['bubble'], + ]); + break; + + case 'syslog': + $definition->setArguments([ + $handler['ident'], + $handler['facility'], + $handler['level'], + $handler['bubble'], + $handler['logopts'], + ]); + break; + + case 'syslogudp': + $definition->setArguments([ + $handler['host'], + $handler['port'], + $handler['facility'], + $handler['level'], + $handler['bubble'], + ]); + if ($handler['ident']) { + $definition->addArgument($handler['ident']); + } + break; + + case 'swift_mailer': + $mailer = $handler['mailer'] ?: 'mailer'; + if (isset($handler['email_prototype'])) { + if (!empty($handler['email_prototype']['method'])) { + $prototype = [new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']]; + } else { + $prototype = new Reference($handler['email_prototype']['id']); + } } else { - $prototype = new Reference($handler['email_prototype']['id']); + $messageFactory = new Definition('Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory'); + $messageFactory->setLazy(true); + $messageFactory->setPublic(false); + $messageFactory->setArguments([ + new Reference($mailer), + $handler['from_email'], + $handler['to_email'], + $handler['subject'], + $handler['content_type'], + ]); + + $messageFactoryId = \sprintf('%s.mail_message_factory', $handlerId); + $container->setDefinition($messageFactoryId, $messageFactory); + // set the prototype as a callable + $prototype = [new Reference($messageFactoryId), 'createMessage']; } - } else { - $messageFactory = new Definition('Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory'); - $messageFactory->setLazy(true); - $messageFactory->setPublic(false); - $messageFactory->setArguments([ + $definition->setArguments([ new Reference($mailer), - $handler['from_email'], - $handler['to_email'], - $handler['subject'], - $handler['content_type'] + $prototype, + $handler['level'], + $handler['bubble'], ]); - $messageFactoryId = sprintf('%s.mail_message_factory', $handlerId); - $container->setDefinition($messageFactoryId, $messageFactory); - // set the prototype as a callable - $prototype = [new Reference($messageFactoryId), 'createMessage']; - } - $definition->setArguments([ - new Reference($mailer), - $prototype, - $handler['level'], - $handler['bubble'], - ]); - - $this->swiftMailerHandlers[] = $handlerId; - $definition->addTag('kernel.event_listener', ['event' => 'kernel.terminate', 'method' => 'onKernelTerminate']); - $definition->addTag('kernel.event_listener', ['event' => 'console.terminate', 'method' => 'onCliTerminate']); - break; - - case 'native_mailer': - $definition->setArguments([ - $handler['to_email'], - $handler['subject'], - $handler['from_email'], - $handler['level'], - $handler['bubble'], - ]); - if (!empty($handler['headers'])) { - $definition->addMethodCall('addHeader', [$handler['headers']]); - } - break; + $this->swiftMailerHandlers[] = $handlerId; + $definition->addTag('kernel.event_listener', ['event' => 'kernel.terminate', 'method' => 'onKernelTerminate']); + $definition->addTag('kernel.event_listener', ['event' => 'console.terminate', 'method' => 'onCliTerminate']); + break; - case 'symfony_mailer': - $mailer = $handler['mailer'] ?: 'mailer.mailer'; - if (isset($handler['email_prototype'])) { - if (!empty($handler['email_prototype']['method'])) { - $prototype = [new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']]; + case 'native_mailer': + $definition->setArguments([ + $handler['to_email'], + $handler['subject'], + $handler['from_email'], + $handler['level'], + $handler['bubble'], + ]); + if (!empty($handler['headers'])) { + $definition->addMethodCall('addHeader', [$handler['headers']]); + } + break; + + case 'symfony_mailer': + $mailer = $handler['mailer'] ?: 'mailer.mailer'; + if (isset($handler['email_prototype'])) { + if (!empty($handler['email_prototype']['method'])) { + $prototype = [new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']]; + } else { + $prototype = new Reference($handler['email_prototype']['id']); + } } else { - $prototype = new Reference($handler['email_prototype']['id']); + $prototype = (new Definition('Symfony\Component\Mime\Email')) + ->setPublic(false) + ->addMethodCall('from', [$handler['from_email']]) + ->addMethodCall('to', $handler['to_email']) + ->addMethodCall('subject', [$handler['subject']]); } - } else { - $prototype = (new Definition('Symfony\Component\Mime\Email')) - ->setPublic(false) - ->addMethodCall('from', [$handler['from_email']]) - ->addMethodCall('to', $handler['to_email']) - ->addMethodCall('subject', [$handler['subject']]); - } - $definition->setArguments([ - new Reference($mailer), - $prototype, - $handler['level'], - $handler['bubble'], - ]); - break; + $definition->setArguments([ + new Reference($mailer), + $prototype, + $handler['level'], + $handler['bubble'], + ]); + break; - case 'socket': - $definition->setArguments([ - $handler['connection_string'], - $handler['level'], - $handler['bubble'], - ]); - if (isset($handler['timeout'])) { - $definition->addMethodCall('setTimeout', [$handler['timeout']]); - } - if (isset($handler['connection_timeout'])) { - $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); - } - if (isset($handler['persistent'])) { - $definition->addMethodCall('setPersistent', [$handler['persistent']]); - } - break; - - case 'pushover': - $definition->setArguments([ - $handler['token'], - $handler['user'], - $handler['title'], - $handler['level'], - $handler['bubble'], - ]); - if (isset($handler['timeout'])) { - $definition->addMethodCall('setTimeout', [$handler['timeout']]); - } - if (isset($handler['connection_timeout'])) { - $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); - } - break; - - case 'hipchat': - $definition->setArguments([ - $handler['token'], - $handler['room'], - $handler['nickname'], - $handler['notify'], - $handler['level'], - $handler['bubble'], - $handler['use_ssl'], - $handler['message_format'], - !empty($handler['host']) ? $handler['host'] : 'api.hipchat.com', - !empty($handler['api_version']) ? $handler['api_version'] : 'v1', - ]); - if (isset($handler['timeout'])) { - $definition->addMethodCall('setTimeout', [$handler['timeout']]); - } - if (isset($handler['connection_timeout'])) { - $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); - } - break; - - case 'slack': - $definition->setArguments([ - $handler['token'], - $handler['channel'], - $handler['bot_name'], - $handler['use_attachment'], - $handler['icon_emoji'], - $handler['level'], - $handler['bubble'], - $handler['use_short_attachment'], - $handler['include_extra'], - ]); - if (isset($handler['timeout'])) { - $definition->addMethodCall('setTimeout', [$handler['timeout']]); - } - if (isset($handler['connection_timeout'])) { - $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); - } - break; - - case 'slackwebhook': - $definition->setArguments([ - $handler['webhook_url'], - $handler['channel'], - $handler['bot_name'], - $handler['use_attachment'], - $handler['icon_emoji'], - $handler['use_short_attachment'], - $handler['include_extra'], - $handler['level'], - $handler['bubble'], - ]); - break; - - case 'slackbot': - $definition->setArguments([ - $handler['team'], - $handler['token'], - urlencode($handler['channel']), - $handler['level'], - $handler['bubble'], - ]); - break; + case 'socket': + $definition->setArguments([ + $handler['connection_string'], + $handler['level'], + $handler['bubble'], + ]); + if (isset($handler['timeout'])) { + $definition->addMethodCall('setTimeout', [$handler['timeout']]); + } + if (isset($handler['connection_timeout'])) { + $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); + } + if (isset($handler['persistent'])) { + $definition->addMethodCall('setPersistent', [$handler['persistent']]); + } + break; + + case 'pushover': + $definition->setArguments([ + $handler['token'], + $handler['user'], + $handler['title'], + $handler['level'], + $handler['bubble'], + ]); + if (isset($handler['timeout'])) { + $definition->addMethodCall('setTimeout', [$handler['timeout']]); + } + if (isset($handler['connection_timeout'])) { + $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); + } + break; + + case 'hipchat': + $definition->setArguments([ + $handler['token'], + $handler['room'], + $handler['nickname'], + $handler['notify'], + $handler['level'], + $handler['bubble'], + $handler['use_ssl'], + $handler['message_format'], + !empty($handler['host']) ? $handler['host'] : 'api.hipchat.com', + !empty($handler['api_version']) ? $handler['api_version'] : 'v1', + ]); + if (isset($handler['timeout'])) { + $definition->addMethodCall('setTimeout', [$handler['timeout']]); + } + if (isset($handler['connection_timeout'])) { + $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); + } + break; + + case 'slack': + $definition->setArguments([ + $handler['token'], + $handler['channel'], + $handler['bot_name'], + $handler['use_attachment'], + $handler['icon_emoji'], + $handler['level'], + $handler['bubble'], + $handler['use_short_attachment'], + $handler['include_extra'], + ]); + if (isset($handler['timeout'])) { + $definition->addMethodCall('setTimeout', [$handler['timeout']]); + } + if (isset($handler['connection_timeout'])) { + $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); + } + break; + + case 'slackwebhook': + $definition->setArguments([ + $handler['webhook_url'], + $handler['channel'], + $handler['bot_name'], + $handler['use_attachment'], + $handler['icon_emoji'], + $handler['use_short_attachment'], + $handler['include_extra'], + $handler['level'], + $handler['bubble'], + ]); + break; + + case 'slackbot': + $definition->setArguments([ + $handler['team'], + $handler['token'], + urlencode($handler['channel']), + $handler['level'], + $handler['bubble'], + ]); + break; - case 'cube': - $definition->setArguments([ - $handler['url'], - $handler['level'], - $handler['bubble'], - ]); - break; - - case 'amqp': - $definition->setArguments([ - new Reference($handler['exchange']), - $handler['exchange_name'], - $handler['level'], - $handler['bubble'], - ]); - break; + case 'cube': + $definition->setArguments([ + $handler['url'], + $handler['level'], + $handler['bubble'], + ]); + break; + + case 'amqp': + $definition->setArguments([ + new Reference($handler['exchange']), + $handler['exchange_name'], + $handler['level'], + $handler['bubble'], + ]); + break; - case 'error_log': - $definition->setArguments([ - $handler['message_type'], - $handler['level'], - $handler['bubble'], - ]); - break; + case 'error_log': + $definition->setArguments([ + $handler['message_type'], + $handler['level'], + $handler['bubble'], + ]); + break; - case 'sentry': - if (null !== $handler['hub_id']) { - $hub = new Reference($handler['hub_id']); - } else { - if (null !== $handler['client_id']) { - $clientId = $handler['client_id']; + case 'sentry': + if (null !== $handler['hub_id']) { + $hub = new Reference($handler['hub_id']); } else { - $options = new Definition( - 'Sentry\\Options', - [['dsn' => $handler['dsn']]] - ); + if (null !== $handler['client_id']) { + $clientId = $handler['client_id']; + } else { + $options = new Definition( + 'Sentry\\Options', + [['dsn' => $handler['dsn']]] + ); - if (!empty($handler['environment'])) { - $options->addMethodCall('setEnvironment', [$handler['environment']]); - } + if (!empty($handler['environment'])) { + $options->addMethodCall('setEnvironment', [$handler['environment']]); + } - if (!empty($handler['release'])) { - $options->addMethodCall('setRelease', [$handler['release']]); - } + if (!empty($handler['release'])) { + $options->addMethodCall('setRelease', [$handler['release']]); + } - $builder = new Definition('Sentry\\ClientBuilder', [$options]); + $builder = new Definition('Sentry\\ClientBuilder', [$options]); - $client = new Definition('Sentry\\Client'); - $client->setFactory([$builder, 'getClient']); + $client = new Definition('Sentry\\Client'); + $client->setFactory([$builder, 'getClient']); - $clientId = 'monolog.sentry.client.'.sha1($handler['dsn']); - $container->setDefinition($clientId, $client); + $clientId = 'monolog.sentry.client.'.sha1($handler['dsn']); + $container->setDefinition($clientId, $client); - if (!$container->hasAlias('Sentry\\ClientInterface')) { - $container->setAlias('Sentry\\ClientInterface', $clientId); + if (!$container->hasAlias('Sentry\\ClientInterface')) { + $container->setAlias('Sentry\\ClientInterface', $clientId); + } } - } - $hub = new Definition( - 'Sentry\\State\\Hub', - [new Reference($clientId)] - ); - $container->setDefinition(sprintf('monolog.handler.%s.hub', $name), $hub); + $hub = new Definition( + 'Sentry\\State\\Hub', + [new Reference($clientId)] + ); + $container->setDefinition(\sprintf('monolog.handler.%s.hub', $name), $hub); - // can't set the hub to the current hub, getting into a recursion otherwise... - //$hub->addMethodCall('setCurrent', array($hub)); - } + // can't set the hub to the current hub, getting into a recursion otherwise... + // $hub->addMethodCall('setCurrent', array($hub)); + } - $definition->setArguments([ - $hub, - $handler['level'], - $handler['bubble'], - $handler['fill_extra_context'], - ]); - break; - - case 'raven': - if (null !== $handler['client_id']) { - $clientId = $handler['client_id']; - } else { - $client = new Definition('Raven_Client', [ - $handler['dsn'], - [ - 'auto_log_stacks' => $handler['auto_log_stacks'], - 'environment' => $handler['environment'] - ] + $definition->setArguments([ + $hub, + $handler['level'], + $handler['bubble'], + $handler['fill_extra_context'], ]); - $client->setPublic(false); - $clientId = 'monolog.raven.client.'.sha1($handler['dsn']); - $container->setDefinition($clientId, $client); - } - $definition->setArguments([ - new Reference($clientId), - $handler['level'], - $handler['bubble'], - ]); - if (!empty($handler['release'])) { - $definition->addMethodCall('setRelease', [$handler['release']]); - } - break; + break; - case 'loggly': - $definition->setArguments([ - $handler['token'], - $handler['level'], - $handler['bubble'], - ]); - if (!empty($handler['tags'])) { - $definition->addMethodCall('setTag', [implode(',', $handler['tags'])]); - } - break; - - case 'logentries': - $definition->setArguments([ - $handler['token'], - $handler['use_ssl'], - $handler['level'], - $handler['bubble'], - ]); - if (isset($handler['timeout'])) { - $definition->addMethodCall('setTimeout', [$handler['timeout']]); - } - if (isset($handler['connection_timeout'])) { - $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); - } - break; - - case 'insightops': - $definition->setArguments([ - $handler['token'], - $handler['region'] ? $handler['region'] : 'us', - $handler['use_ssl'], - $handler['level'], - $handler['bubble'], - ]); - break; + case 'raven': + if (null !== $handler['client_id']) { + $clientId = $handler['client_id']; + } else { + $client = new Definition('Raven_Client', [ + $handler['dsn'], + [ + 'auto_log_stacks' => $handler['auto_log_stacks'], + 'environment' => $handler['environment'], + ], + ]); + $client->setPublic(false); + $clientId = 'monolog.raven.client.'.sha1($handler['dsn']); + $container->setDefinition($clientId, $client); + } + $definition->setArguments([ + new Reference($clientId), + $handler['level'], + $handler['bubble'], + ]); + if (!empty($handler['release'])) { + $definition->addMethodCall('setRelease', [$handler['release']]); + } + break; - case 'flowdock': - $definition->setArguments([ - $handler['token'], - $handler['level'], - $handler['bubble'], - ]); + case 'loggly': + $definition->setArguments([ + $handler['token'], + $handler['level'], + $handler['bubble'], + ]); + if (!empty($handler['tags'])) { + $definition->addMethodCall('setTag', [implode(',', $handler['tags'])]); + } + break; + + case 'logentries': + $definition->setArguments([ + $handler['token'], + $handler['use_ssl'], + $handler['level'], + $handler['bubble'], + ]); + if (isset($handler['timeout'])) { + $definition->addMethodCall('setTimeout', [$handler['timeout']]); + } + if (isset($handler['connection_timeout'])) { + $definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]); + } + break; + + case 'insightops': + $definition->setArguments([ + $handler['token'], + $handler['region'] ?: 'us', + $handler['use_ssl'], + $handler['level'], + $handler['bubble'], + ]); + break; - if (empty($handler['formatter'])) { - $formatter = new Definition("Monolog\Formatter\FlowdockFormatter", [ - $handler['source'], - $handler['from_email'], + case 'flowdock': + $definition->setArguments([ + $handler['token'], + $handler['level'], + $handler['bubble'], ]); - $formatterId = 'monolog.flowdock.formatter.'.sha1($handler['source'].'|'.$handler['from_email']); - $formatter->setPublic(false); - $container->setDefinition($formatterId, $formatter); - $definition->addMethodCall('setFormatter', [new Reference($formatterId)]); - } - break; - - case 'rollbar': - if (!empty($handler['id'])) { - $rollbarId = $handler['id']; - } else { - $config = $handler['config'] ?: []; - $config['access_token'] = $handler['token']; - $rollbar = new Definition('RollbarNotifier', [ - $config, + if (empty($handler['formatter'])) { + $formatter = new Definition("Monolog\Formatter\FlowdockFormatter", [ + $handler['source'], + $handler['from_email'], + ]); + $formatterId = 'monolog.flowdock.formatter.'.sha1($handler['source'].'|'.$handler['from_email']); + $formatter->setPublic(false); + $container->setDefinition($formatterId, $formatter); + + $definition->addMethodCall('setFormatter', [new Reference($formatterId)]); + } + break; + + case 'rollbar': + if (!empty($handler['id'])) { + $rollbarId = $handler['id']; + } else { + $config = $handler['config'] ?: []; + $config['access_token'] = $handler['token']; + $rollbar = new Definition('RollbarNotifier', [ + $config, + ]); + $rollbarId = 'monolog.rollbar.notifier.'.sha1(json_encode($config)); + $rollbar->setPublic(false); + $container->setDefinition($rollbarId, $rollbar); + } + + $definition->setArguments([ + new Reference($rollbarId), + $handler['level'], + $handler['bubble'], ]); - $rollbarId = 'monolog.rollbar.notifier.'.sha1(json_encode($config)); - $rollbar->setPublic(false); - $container->setDefinition($rollbarId, $rollbar); - } + break; + case 'newrelic': + $definition->setArguments([ + $handler['level'], + $handler['bubble'], + $handler['app_name'], + ]); + break; + case 'server_log': + $definition->setArguments([ + $handler['host'], + $handler['level'], + $handler['bubble'], + ]); + break; + case 'sampling': + $nestedHandlerId = $this->getHandlerId($handler['handler']); + $this->markNestedHandler($nestedHandlerId); - $definition->setArguments([ - new Reference($rollbarId), - $handler['level'], - $handler['bubble'], - ]); - break; - case 'newrelic': - $definition->setArguments([ - $handler['level'], - $handler['bubble'], - $handler['app_name'], - ]); - break; - case 'server_log': - $definition->setArguments([ - $handler['host'], - $handler['level'], - $handler['bubble'], - ]); - break; - case 'sampling': - $nestedHandlerId = $this->getHandlerId($handler['handler']); - $this->markNestedHandler($nestedHandlerId); - - $definition->setArguments([ - new Reference($nestedHandlerId), - $handler['factor'], - ]); - break; - - // Handlers using the constructor of AbstractHandler without adding their own arguments - case 'browser_console': - case 'test': - case 'null': - case 'noop': - case 'debug': - $definition->setArguments([ - $handler['level'], - $handler['bubble'], - ]); - break; + $definition->setArguments([ + new Reference($nestedHandlerId), + $handler['factor'], + ]); + break; + + // Handlers using the constructor of AbstractHandler without adding their own arguments + case 'browser_console': + case 'test': + case 'null': + case 'noop': + case 'debug': + $definition->setArguments([ + $handler['level'], + $handler['bubble'], + ]); + break; - default: - $nullWarning = ''; - if ($handler['type'] == '') { - $nullWarning = ', if you meant to define a null handler in a yaml config, make sure you quote "null" so it does not get converted to a php null'; - } + default: + $nullWarning = ''; + if ('' == $handler['type']) { + $nullWarning = ', if you meant to define a null handler in a yaml config, make sure you quote "null" so it does not get converted to a php null'; + } - throw new \InvalidArgumentException(sprintf('Invalid handler type "%s" given for handler "%s"' . $nullWarning, $handler['type'], $name)); + throw new \InvalidArgumentException(\sprintf('Invalid handler type "%s" given for handler "%s"'.$nullWarning, $handler['type'], $name)); } if (!empty($handler['nested']) && true === $handler['nested']) { @@ -929,7 +927,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $definition->addMethodCall('setFormatter', [new Reference($handler['formatter'])]); } - if (!in_array($handlerId, $this->nestedHandlers) && is_subclass_of($handlerClass, ResettableInterface::class)) { + if (!\in_array($handlerId, $this->nestedHandlers) && is_subclass_of($handlerClass, ResettableInterface::class)) { $definition->addTag('kernel.reset', ['method' => 'reset']); } @@ -940,7 +938,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler private function markNestedHandler($nestedHandlerId) { - if (in_array($nestedHandlerId, $this->nestedHandlers)) { + if (\in_array($nestedHandlerId, $this->nestedHandlers)) { return; } @@ -949,7 +947,7 @@ private function markNestedHandler($nestedHandlerId) private function getHandlerId($name) { - return sprintf('monolog.handler.%s', $name); + return \sprintf('monolog.handler.%s', $name); } private function getHandlerClassByType($handlerType) @@ -1022,31 +1020,31 @@ private function getHandlerClassByType($handlerType) if (Logger::API >= 2) { $typeToClassMapping = array_merge($typeToClassMapping, $v2HandlerTypesAdded); - foreach($v2HandlerTypesRemoved as $v2HandlerTypeRemoved) { + foreach ($v2HandlerTypesRemoved as $v2HandlerTypeRemoved) { unset($typeToClassMapping[$v2HandlerTypeRemoved]); } } if (Logger::API >= 3) { - foreach($v3HandlerTypesRemoved as $v3HandlerTypeRemoved) { + foreach ($v3HandlerTypesRemoved as $v3HandlerTypeRemoved) { unset($typeToClassMapping[$v3HandlerTypeRemoved]); } } if (!isset($typeToClassMapping[$handlerType])) { - if (Logger::API === 1 && array_key_exists($handlerType, $v2HandlerTypesAdded)) { - throw new \InvalidArgumentException(sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType)); + if (Logger::API === 1 && \array_key_exists($handlerType, $v2HandlerTypesAdded)) { + throw new \InvalidArgumentException(\sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType)); } - if (Logger::API >= 2 && array_key_exists($handlerType, $v2HandlerTypesRemoved)) { - throw new \InvalidArgumentException(sprintf('"%s" was removed in Monolog v2.', $handlerType)); + if (Logger::API >= 2 && \array_key_exists($handlerType, $v2HandlerTypesRemoved)) { + throw new \InvalidArgumentException(\sprintf('"%s" was removed in Monolog v2.', $handlerType)); } - if (Logger::API >= 3 && array_key_exists($handlerType, $v3HandlerTypesRemoved)) { - throw new \InvalidArgumentException(sprintf('"%s" was removed in Monolog v3.', $handlerType)); + if (Logger::API >= 3 && \array_key_exists($handlerType, $v3HandlerTypesRemoved)) { + throw new \InvalidArgumentException(\sprintf('"%s" was removed in Monolog v3.', $handlerType)); } - throw new \InvalidArgumentException(sprintf('There is no handler class defined for handler "%s".', $handlerType)); + throw new \InvalidArgumentException(\sprintf('There is no handler class defined for handler "%s".', $handlerType)); } return $typeToClassMapping[$handlerType]; diff --git a/MonologBundle.php b/MonologBundle.php index 11b835ad..baae67f2 100644 --- a/MonologBundle.php +++ b/MonologBundle.php @@ -14,13 +14,12 @@ use Monolog\Formatter\JsonFormatter; use Monolog\Formatter\LineFormatter; use Monolog\Handler\HandlerInterface; -use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddSwiftMailerTransportPass; -use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; -use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\DebugHandlerPass; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddSwiftMailerTransportPass; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\FixEmptyLoggerPass; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Bundle\Bundle; /** * @author Jordi Boggiano @@ -44,6 +43,7 @@ public function build(ContainerBuilder $container) /** * @internal + * * @return void */ public static function includeStacktraces(HandlerInterface $handler) diff --git a/SwiftMailer/MessageFactory.php b/SwiftMailer/MessageFactory.php index f2db2497..16b79115 100644 --- a/SwiftMailer/MessageFactory.php +++ b/SwiftMailer/MessageFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\MonologBundle\SwiftMailer; /** - * Helps create Swift_Message objects, lazily + * Helps create Swift_Message objects, lazily. * * @author Ryan Weaver */ @@ -38,10 +38,11 @@ public function __construct(\Swift_Mailer $mailer, $fromEmail, $toEmail, $subjec } /** - * Creates a Swift_Message template that will be used to send the log message + * Creates a Swift_Message template that will be used to send the log message. * * @param string $content formatted email body to be sent * @param array $records Log records that formed the content + * * @return \Swift_Message */ public function createMessage($content, array $records) diff --git a/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php b/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php index 746a3999..c11c2a33 100644 --- a/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php @@ -19,7 +19,6 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Loader\FileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; diff --git a/Tests/DependencyInjection/Compiler/AddSwiftMailerTransportPassTest.php b/Tests/DependencyInjection/Compiler/AddSwiftMailerTransportPassTest.php index 79d5beb5..bb743fbe 100644 --- a/Tests/DependencyInjection/Compiler/AddSwiftMailerTransportPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddSwiftMailerTransportPassTest.php @@ -36,17 +36,17 @@ protected function doSetUp() $this->definition->expects($this->any()) ->method('getArgument') ->with(0) - ->will($this->returnValue(new Reference('swiftmailer'))); + ->willReturn(new Reference('swiftmailer')); $this->container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder') ->setMethods(['getParameter', 'getDefinition', 'hasDefinition', 'addMethodCall'])->getMock(); $this->container->expects($this->any()) ->method('getParameter') ->with('monolog.swift_mailer.handlers') - ->will($this->returnValue(['foo'])); + ->willReturn(['foo']); $this->container->expects($this->any()) ->method('getDefinition') ->with('foo') - ->will($this->returnValue($this->definition)); + ->willReturn($this->definition); } public function testWithRealTransport() @@ -55,7 +55,7 @@ public function testWithRealTransport() ->expects($this->any()) ->method('hasDefinition') ->with('swiftmailer.transport.real') - ->will($this->returnValue(true)); + ->willReturn(true); $this->definition ->expects($this->once()) ->method('addMethodCall') @@ -72,12 +72,12 @@ public function testWithoutRealTransport() $this->container ->expects($this->any()) ->method('hasDefinition') - ->will($this->returnValueMap( + ->willReturnMap( [ ['swiftmailer.transport.real', false], ['swiftmailer.transport', true], ] - )); + ); $this->definition ->expects($this->once()) ->method('addMethodCall') diff --git a/Tests/DependencyInjection/Compiler/FixEmptyLoggerPassTest.php b/Tests/DependencyInjection/Compiler/FixEmptyLoggerPassTest.php index d68478de..ed5ba7f8 100644 --- a/Tests/DependencyInjection/Compiler/FixEmptyLoggerPassTest.php +++ b/Tests/DependencyInjection/Compiler/FixEmptyLoggerPassTest.php @@ -20,7 +20,7 @@ class FixEmptyLoggerPassTest extends TestCase public function testProcess() { $loggerChannelPass = $this->getMockBuilder('Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass')->getMock(); - $loggerChannelPass->expects($this->any())->method('getChannels')->will($this->returnValue(['foo', 'bar'])); + $loggerChannelPass->expects($this->any())->method('getChannels')->willReturn(['foo', 'bar']); $container = new ContainerBuilder(); $container->register('monolog.logger.foo', 'Monolog\Logger'); diff --git a/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php b/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php index 7ed07452..3b539e09 100644 --- a/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php +++ b/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php @@ -33,8 +33,8 @@ public function testProcess() // pushHandlers for service "test" $expected = [ 'test' => ['monolog.handler.a', 'monolog.handler.b', 'monolog.handler.c'], - 'foo' => ['monolog.handler.b'], - 'bar' => ['monolog.handler.b', 'monolog.handler.c'], + 'foo' => ['monolog.handler.b'], + 'bar' => ['monolog.handler.b', 'monolog.handler.c'], ]; foreach ($expected as $serviceName => $handlers) { @@ -42,9 +42,9 @@ public function testProcess() $channel = $container->getDefinition((string) $service->getArgument(1)); $calls = $channel->getMethodCalls(); - $this->assertCount(count($handlers), $calls); + $this->assertCount(\count($handlers), $calls); foreach ($handlers as $i => $handler) { - list($methodName, $arguments) = $calls[$i]; + [$methodName, $arguments] = $calls[$i]; $this->assertEquals('pushHandler', $methodName); $this->assertCount(1, $arguments); $this->assertEquals($handler, (string) $arguments[0]); @@ -60,7 +60,7 @@ public function testTypeHintedAliasesExistForEachChannel() $expectedChannels = ['test', 'foo', 'bar', 'additional']; foreach ($expectedChannels as $channelName) { - $aliasName = LoggerInterface::class.' $' .$channelName.'Logger'; + $aliasName = LoggerInterface::class.' $'.$channelName.'Logger'; $this->assertTrue($container->hasAlias($aliasName), 'type-hinted alias should be exists for each logger channel'); } } @@ -169,13 +169,13 @@ private function getContainer() $container->setParameter('monolog.handlers_to_channels', [ 'monolog.handler.a' => [ 'type' => 'inclusive', - 'elements' => ['test'] + 'elements' => ['test'], ], 'monolog.handler.b' => null, 'monolog.handler.c' => [ 'type' => 'exclusive', - 'elements' => ['foo'] - ] + 'elements' => ['foo'], + ], ]); $container->getCompilerPassConfig()->setOptimizationPasses([]); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 38847364..516565e0 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -28,8 +28,8 @@ public function testProcessSimpleCase() { $configs = [ [ - 'handlers' => ['foobar' => ['type' => 'stream', 'path' => '/foo/bar']] - ] + 'handlers' => ['foobar' => ['type' => 'stream', 'path' => '/foo/bar']], + ], ]; $config = $this->process($configs); @@ -45,7 +45,7 @@ public function provideProcessStringChannels() { return [ ['foo', 'foo', true], - ['!foo', 'foo', false] + ['!foo', 'foo', false], ]; } @@ -60,10 +60,10 @@ public function testProcessStringChannels($string, $expectedString, $isInclusive 'foobar' => [ 'type' => 'stream', 'path' => '/foo/bar', - 'channels' => $string - ] - ] - ] + 'channels' => $string, + ], + ], + ], ]; $config = $this->process($configs); @@ -77,13 +77,13 @@ public function provideGelfPublisher() { return [ [ - 'gelf.publisher' + 'gelf.publisher', ], [ [ - 'id' => 'gelf.publisher' - ] - ] + 'id' => 'gelf.publisher', + ], + ], ]; } @@ -99,8 +99,8 @@ public function testGelfPublisherService($publisher) 'type' => 'gelf', 'publisher' => $publisher, ], - ] - ] + ], + ], ]; $config = $this->process($configs); @@ -118,15 +118,15 @@ public function testArrays() 'foo' => [ 'type' => 'stream', 'path' => '/foo', - 'channels' => ['A', 'B'] + 'channels' => ['A', 'B'], ], 'bar' => [ 'type' => 'stream', 'path' => '/foo', - 'channels' => ['!C', '!D'] + 'channels' => ['!C', '!D'], ], - ] - ] + ], + ], ]; $config = $this->process($configs); @@ -152,10 +152,10 @@ public function testInvalidArrays() 'foo' => [ 'type' => 'stream', 'path' => '/foo', - 'channels' => ['A', '!B'] - ] - ] - ] + 'channels' => ['A', '!B'], + ], + ], + ], ]; $this->expectException(InvalidConfigurationException::class); @@ -172,16 +172,16 @@ public function testMergingInvalidChannels() 'type' => 'stream', 'path' => '/foo', 'channels' => 'A', - ] - ] + ], + ], ], [ 'handlers' => [ 'foo' => [ 'channels' => '!B', - ] - ] - ] + ], + ], + ], ]; $this->expectException(InvalidConfigurationException::class); @@ -192,7 +192,7 @@ public function testMergingInvalidChannels() /** @group legacy */ public function testWithSwiftMailerHandler() { - if (\Monolog\Logger::API >= 3) { + if (Logger::API >= 3) { $this->markTestSkipped('This test requires Monolog v1 or v2'); } @@ -204,14 +204,14 @@ public function testWithSwiftMailerHandler() 'from_email' => 'foo@bar.com', 'to_email' => 'foo@bar.com', 'subject' => 'Subject', - 'mailer' => 'mailer', + 'mailer' => 'mailer', 'email_prototype' => [ 'id' => 'monolog.prototype', - 'method' => 'getPrototype' - ] - ] - ] - ] + 'method' => 'getPrototype', + ], + ], + ], + ], ]; $config = $this->process($configs); @@ -231,19 +231,19 @@ public function testWithElasticsearchHandler() 'elasticsearch' => [ 'type' => 'elasticsearch', 'elasticsearch' => [ - 'id' => 'elastica.client' + 'id' => 'elastica.client', ], 'index' => 'my-index', 'document_type' => 'my-record', - 'ignore_error' => true - ] - ] - ] + 'ignore_error' => true, + ], + ], + ], ]; $config = $this->process($configs); - $this->assertEquals(true, $config['handlers']['elasticsearch']['ignore_error']); + $this->assertTrue($config['handlers']['elasticsearch']['ignore_error']); $this->assertEquals('my-record', $config['handlers']['elasticsearch']['document_type']); $this->assertEquals('my-index', $config['handlers']['elasticsearch']['index']); } @@ -257,9 +257,9 @@ public function testWithTelegramBotHandler() 'type' => 'telegram', 'token' => 'bot-token', 'channel' => '-100', - ] - ] - ] + ], + ], + ], ]; $config = $this->process($configs); @@ -278,11 +278,11 @@ public function testWithConsoleHandler() 'verbosity_levels' => [ 'VERBOSITY_NORMAL' => 'NOTICE', 'verbosity_verbose' => 'info', - 'VERBOSITY_very_VERBOSE' => '200' - ] - ] - ] - ] + 'VERBOSITY_very_VERBOSE' => '200', + ], + ], + ], + ], ]; $config = $this->process($configs); @@ -293,8 +293,8 @@ public function testWithConsoleHandler() OutputInterface::VERBOSITY_VERBOSE => Logger::INFO, OutputInterface::VERBOSITY_VERY_VERBOSE => 200, OutputInterface::VERBOSITY_QUIET => Logger::ERROR, - OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG - ], $config['handlers']['console']['verbosity_levels']); + OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG, + ], $config['handlers']['console']['verbosity_levels']); } public function testWithType() @@ -307,11 +307,11 @@ public function testWithType() 'path' => '/foo', 'channels' => [ 'type' => 'inclusive', - 'elements' => ['A', 'B'] - ] - ] - ] - ] + 'elements' => ['A', 'B'], + ], + ], + ], + ], ]; $config = $this->process($configs); @@ -336,10 +336,10 @@ public function testWithFilePermission() 'bar' => [ 'type' => 'stream', 'path' => '/bar', - 'file_permission' => 0777 - ] - ] - ] + 'file_permission' => 0777, + ], + ], + ], ]; $config = $this->process($configs); @@ -362,9 +362,9 @@ public function testWithUseLocking() 'type' => 'rotating_file', 'path' => '/bar', 'use_locking' => true, - ] - ] - ] + ], + ], + ], ]; $config = $this->process($configs); @@ -377,13 +377,12 @@ public function testWithNestedHandler() { $configs = [ [ - 'handlers' => ['foobar' => ['type' => 'stream', 'path' => '/foo/bar', 'nested' => true]] - ] + 'handlers' => ['foobar' => ['type' => 'stream', 'path' => '/foo/bar', 'nested' => true]], + ], ]; $config = $this->process($configs); - $this->assertTrue($config['handlers']['foobar']['nested']); } @@ -399,11 +398,11 @@ public function testWithRedisHandler() 'password' => 'pa$$w0rd', 'port' => 1234, 'database' => 1, - 'key_name' => 'monolog_redis_test' - ] - ] - ] - ] + 'key_name' => 'monolog_redis_test', + ], + ], + ], + ], ]; $config = $this->process($configs); @@ -420,11 +419,11 @@ public function testWithRedisHandler() 'type' => 'predis', 'redis' => [ 'host' => '127.0.1.1', - 'key_name' => 'monolog_redis_test' - ] - ] - ] - ] + 'key_name' => 'monolog_redis_test', + ], + ], + ], + ], ]; $config = $this->process($configs); diff --git a/Tests/DependencyInjection/DependencyInjectionTest.php b/Tests/DependencyInjection/DependencyInjectionTest.php index 8fcd6b27..54a4c3f8 100644 --- a/Tests/DependencyInjection/DependencyInjectionTest.php +++ b/Tests/DependencyInjection/DependencyInjectionTest.php @@ -23,7 +23,7 @@ abstract class DependencyInjectionTest extends TestCase */ protected function assertDICDefinitionClass($definition, $expectedClass) { - $this->assertEquals($expectedClass, $definition->getClass(), "Expected Class of the DIC Container Service Definition is wrong."); + $this->assertEquals($expectedClass, $definition->getClass(), 'Expected Class of the DIC Container Service Definition is wrong.'); } protected function assertDICConstructorArguments($definition, $args) @@ -31,13 +31,13 @@ protected function assertDICConstructorArguments($definition, $args) $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '".$definition->getClass()."' don't match."); } - protected function assertDICDefinitionMethodCallAt($pos, $definition, $methodName, array $params = null) + protected function assertDICDefinitionMethodCallAt($pos, $definition, $methodName, ?array $params = null) { $calls = $definition->getMethodCalls(); if (isset($calls[$pos][0])) { $this->assertEquals($methodName, $calls[$pos][0], "Method '".$methodName."' is expected to be called at position $pos."); - if ($params !== null) { + if (null !== $params) { $this->assertEquals($params, $calls[$pos][1], "Expected parameters to methods '".$methodName."' do not match the actual parameters."); } } else { diff --git a/Tests/DependencyInjection/FixtureMonologExtensionTest.php b/Tests/DependencyInjection/FixtureMonologExtensionTest.php index 72bc46c5..dd0046f5 100644 --- a/Tests/DependencyInjection/FixtureMonologExtensionTest.php +++ b/Tests/DependencyInjection/FixtureMonologExtensionTest.php @@ -13,7 +13,6 @@ use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use Monolog\Processor\PsrLogMessageProcessor; -use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -188,7 +187,7 @@ public function testMultipleEmailRecipients() 'error@example.com', ['dev1@example.com', 'dev2@example.com'], 'An Error Occurred!', - null + null, ], $container->getDefinition('monolog.handler.swift.mail_message_factory')->getArguments()); } diff --git a/Tests/DependencyInjection/Fixtures/AsMonologProcessor/FooProcessor.php b/Tests/DependencyInjection/Fixtures/AsMonologProcessor/FooProcessor.php index 6571b97b..9427e957 100644 --- a/Tests/DependencyInjection/Fixtures/AsMonologProcessor/FooProcessor.php +++ b/Tests/DependencyInjection/Fixtures/AsMonologProcessor/FooProcessor.php @@ -20,4 +20,4 @@ class FooProcessor public function __invoke(): void { } -} \ No newline at end of file +} diff --git a/Tests/DependencyInjection/Fixtures/AsMonologProcessor/RedeclareMethodProcessor.php b/Tests/DependencyInjection/Fixtures/AsMonologProcessor/RedeclareMethodProcessor.php index baf4f9f8..2f26bdc7 100644 --- a/Tests/DependencyInjection/Fixtures/AsMonologProcessor/RedeclareMethodProcessor.php +++ b/Tests/DependencyInjection/Fixtures/AsMonologProcessor/RedeclareMethodProcessor.php @@ -19,4 +19,4 @@ class RedeclareMethodProcessor public function __invoke(): void { } -} \ No newline at end of file +} diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index 2888c686..a0c82005 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -11,24 +11,23 @@ namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection; -use InvalidArgumentException; use Monolog\Attribute\AsMonologProcessor; use Monolog\Attribute\WithMonologChannel; use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use Monolog\Handler\RollbarHandler; use Monolog\Logger; use Monolog\Processor\UidProcessor; -use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; +use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\ServiceWithChannel; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\HttpFoundation\RequestStack; class MonologExtensionTest extends DependencyInjectionTest @@ -53,7 +52,7 @@ public function testLoadWithDefault() public function testLoadWithCustomValues() { $container = $this->getContainer([['handlers' => [ - 'custom' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666', 'use_locking' => true] + 'custom' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666', 'use_locking' => true], ]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.custom')); @@ -71,7 +70,7 @@ public function testLoadWithNestedHandler() { $container = $this->getContainer([['handlers' => [ 'custom' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666'], - 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666', 'nested' => true] + 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666', 'nested' => true], ]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.custom')); @@ -132,7 +131,7 @@ public function testExceptionWhenInvalidHandler() $container = new ContainerBuilder(); $loader = new MonologExtension(); - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $loader->load([['handlers' => ['main' => ['type' => 'invalid_handler']]]], $container); } @@ -210,7 +209,7 @@ public function testExceptionWhenUsingDebugName() public function testSyslogHandlerWithLogopts() { - $container = $this->getContainer([['handlers' => ['main' => ['type' => 'syslog', 'logopts' => LOG_CONS]]]]); + $container = $this->getContainer([['handlers' => ['main' => ['type' => 'syslog', 'logopts' => \LOG_CONS]]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.main')); @@ -221,7 +220,7 @@ public function testSyslogHandlerWithLogopts() $handler = $container->getDefinition('monolog.handler.main'); $this->assertDICDefinitionClass($handler, 'Monolog\Handler\SyslogHandler'); - $this->assertDICConstructorArguments($handler, [false, 'user', 'DEBUG', true, LOG_CONS]); + $this->assertDICConstructorArguments($handler, [false, 'user', 'DEBUG', true, \LOG_CONS]); } public function testRollbarHandlerCreatesNotifier() @@ -270,7 +269,7 @@ public function testSocketHandler() $container = $this->getContainer([['handlers' => ['socket' => [ 'type' => 'socket', 'timeout' => 1, 'persistent' => true, - 'connection_string' => 'localhost:50505', 'connection_timeout' => '0.6' + 'connection_string' => 'localhost:50505', 'connection_timeout' => '0.6', ]]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.socket')); @@ -315,7 +314,7 @@ public function testRavenHandlerWhenADSNIsSpecified() $dsn = 'http://43f6017361224d098402974103bfc53d:a6a0538fc2934ba2bed32e08741b2cd3@marca.python.live.cheggnet.com:9000/1'; $container = $this->getContainer([['handlers' => ['raven' => [ - 'type' => 'raven', 'dsn' => $dsn + 'type' => 'raven', 'dsn' => $dsn, ]]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.raven')); @@ -339,7 +338,7 @@ public function testRavenHandlerWhenADSNAndAClientAreSpecified() } $container = $this->getContainer([['handlers' => ['raven' => [ - 'type' => 'raven', 'dsn' => 'foobar', 'client_id' => 'raven.client' + 'type' => 'raven', 'dsn' => 'foobar', 'client_id' => 'raven.client', ]]]], ['raven.client' => new Definition('Raven_Client')]); $logger = $container->getDefinition('monolog.logger'); @@ -359,7 +358,7 @@ public function testRavenHandlerWhenAClientIsSpecified() } $container = $this->getContainer([['handlers' => ['raven' => [ - 'type' => 'raven', 'client_id' => 'raven.client' + 'type' => 'raven', 'client_id' => 'raven.client', ]]]], ['raven.client' => new Definition('Raven_Client')]); $logger = $container->getDefinition('monolog.logger'); @@ -385,7 +384,7 @@ public function testSentryHandlerWhenADSNIsSpecified() $dsn = 'http://43f6017361224d098402974103bfc53d:a6a0538fc2934ba2bed32e08741b2cd3@marca.python.live.cheggnet.com:9000/1'; $container = $this->getContainer([['handlers' => ['sentry' => [ - 'type' => 'sentry', 'dsn' => $dsn + 'type' => 'sentry', 'dsn' => $dsn, ]]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.sentry')); @@ -437,8 +436,7 @@ public function testSentryHandlerWhenAClientIsSpecified() [ 'handlers' => [ 'sentry' => [ - 'type' => - 'sentry', + 'type' => 'sentry', 'client_id' => 'sentry.client', ], ], @@ -515,7 +513,7 @@ public function testLogglyHandler() try { $this->getContainer([['handlers' => ['loggly' => [ - 'type' => 'loggly', 'token' => $token, 'tags' => 'x, 1zone ,www.loggly.com,-us,apache$' + 'type' => 'loggly', 'token' => $token, 'tags' => 'x, 1zone ,www.loggly.com,-us,apache$', ]]]]); $this->fail(); } catch (InvalidConfigurationException $e) { @@ -523,7 +521,7 @@ public function testLogglyHandler() } $container = $this->getContainer([['handlers' => ['loggly' => [ - 'type' => 'loggly', 'token' => $token + 'type' => 'loggly', 'token' => $token, ]]]]); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.loggly')); @@ -537,7 +535,7 @@ public function testLogglyHandler() $this->assertDICDefinitionMethodCallAt(0, $handler, 'pushProcessor', [new Reference('monolog.processor.psr_log_message')]); $container = $this->getContainer([['handlers' => ['loggly' => [ - 'type' => 'loggly', 'token' => $token, 'tags' => [' ', 'foo', '', 'bar'] + 'type' => 'loggly', 'token' => $token, 'tags' => [' ', 'foo', '', 'bar'], ]]]]); $handler = $container->getDefinition('monolog.handler.loggly'); $this->assertDICDefinitionMethodCallAt(0, $handler, 'pushProcessor', [new Reference('monolog.processor.psr_log_message')]); @@ -550,7 +548,7 @@ public function testFingersCrossedHandlerWhenExcluded404sAreSpecified() $activation = new Definition(ErrorLevelActivationStrategy::class, ['WARNING']); $container = $this->getContainer([['handlers' => [ 'main' => ['type' => 'fingers_crossed', 'handler' => 'nested', 'excluded_404s' => ['^/foo', '^/bar']], - 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log'] + 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log'], ]]], ['request_stack' => new Definition(RequestStack::class)]); $this->assertTrue($container->hasDefinition('monolog.logger')); @@ -579,9 +577,9 @@ public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified() 'main' => [ 'type' => 'fingers_crossed', 'handler' => 'nested', - 'excluded_http_codes' => [403, 404, [405 => ['^/foo', '^/bar']]] + 'excluded_http_codes' => [403, 404, [405 => ['^/foo', '^/bar']]], ], - 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log'] + 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log'], ]]], ['request_stack' => new Definition(RequestStack::class)]); $this->assertTrue($container->hasDefinition('monolog.logger')); @@ -600,7 +598,7 @@ public function testFingersCrossedHandlerWhenExcludedHttpCodesAreSpecified() [ ['code' => 403, 'urls' => []], ['code' => 404, 'urls' => []], - ['code' => 405, 'urls' => ['^/foo', '^/bar']] + ['code' => 405, 'urls' => ['^/foo', '^/bar']], ], $activation, ]); @@ -621,8 +619,8 @@ public function testV2Removed(array $handlerOptions) return; } - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf('There is no handler class defined for handler "%s".', $handlerOptions['type'])); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage(\sprintf('There is no handler class defined for handler "%s".', $handlerOptions['type'])); $container = new ContainerBuilder(); $loader = new MonologExtension(); @@ -650,9 +648,9 @@ public function testV2AddedOnV1(string $handlerType) return; } - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage( - sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType) + \sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType) ); $container = new ContainerBuilder(); @@ -696,7 +694,7 @@ public function provideLoglevelParameterConfig(): array [ '%log_level%', true, - ] + ], ], 'browser console with envvar level' => [ ['%env(LOG_LEVEL)%' => 'info'], @@ -705,7 +703,7 @@ public function provideLoglevelParameterConfig(): array [ '%env(LOG_LEVEL)%', true, - ] + ], ], 'stream with envvar level null or "~" (in yaml config)' => [ ['%env(LOG_LEVEL)%' => null], @@ -717,7 +715,7 @@ public function provideLoglevelParameterConfig(): array true, null, false, - ] + ], ], 'stream with envvar level' => [ ['%env(LOG_LEVEL)%' => '400'], @@ -729,7 +727,7 @@ public function provideLoglevelParameterConfig(): array true, null, false, - ] + ], ], 'stream with envvar and fallback parameter' => [ ['%env(LOG_LEVEL)%' => '500', '%log_level%' => '%env(LOG_LEVEL)%'], @@ -741,7 +739,7 @@ public function provideLoglevelParameterConfig(): array true, null, false, - ] + ], ], ]; } @@ -770,7 +768,7 @@ public function testProcessorAutoConfiguration() */ public function testAsMonologProcessorAutoconfigurationRedeclareMethod(): void { - if (!\class_exists(AsMonologProcessor::class, true)) { + if (!class_exists(AsMonologProcessor::class, true)) { $this->markTestSkipped('Monolog >= 2.3.6 is needed.'); } @@ -787,7 +785,7 @@ public function testAsMonologProcessorAutoconfigurationRedeclareMethod(): void */ public function testAsMonologProcessorAutoconfiguration(): void { - if (!\class_exists(AsMonologProcessor::class, true) || \property_exists(AsMonologProcessor::class, 'priority')) { + if (!class_exists(AsMonologProcessor::class, true) || property_exists(AsMonologProcessor::class, 'priority')) { $this->markTestSkipped('Monolog >= 2.3.6 and < 3.4.0 is needed.'); } @@ -814,7 +812,7 @@ public function testAsMonologProcessorAutoconfiguration(): void */ public function testAsMonologProcessorAutoconfigurationWithPriority(): void { - if (!\class_exists(AsMonologProcessor::class, true) || !\property_exists(AsMonologProcessor::class, 'priority')) { + if (!class_exists(AsMonologProcessor::class, true) || !property_exists(AsMonologProcessor::class, 'priority')) { $this->markTestSkipped('Monolog >= 3.4.0 is needed.'); }