• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mimmi20 / monolog-factory / 16691402042

02 Aug 2025 07:41AM UTC coverage: 88.181%. Remained the same
16691402042

push

github

web-flow
Merge pull request #882 from mimmi20/dependabot/composer/4.x/development-dependencies-408f3b8041

composer (4.x)(deps-dev): bump the development-dependencies group with 7 updates

2574 of 2919 relevant lines covered (88.18%)

32.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Handler/RollbarHandlerFactory.php
1
<?php
2

3
/**
4
 * This file is part of the mimmi20/monolog-factory package.
5
 *
6
 * Copyright (c) 2022-2025, Thomas Mueller <mimmi20@live.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types = 1);
13

14
namespace Mimmi20\MonologFactory\Handler;
15

16
use InvalidArgumentException;
17
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
18
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
19
use Laminas\ServiceManager\Factory\FactoryInterface;
20
use Mimmi20\MonologFactory\AddFormatterTrait;
21
use Mimmi20\MonologFactory\AddProcessorTrait;
22
use Monolog\Handler\RollbarHandler;
23
use Monolog\Level;
24
use Override;
25
use Psr\Container\ContainerInterface;
26
use Psr\Log\LogLevel;
27
use Rollbar\Config;
28
use Rollbar\RollbarLogger;
29

30
use function array_key_exists;
31
use function is_array;
32
use function sprintf;
33

34
final class RollbarHandlerFactory implements FactoryInterface
35
{
36
    use AddFormatterTrait;
37
    use AddProcessorTrait;
38

39
    /**
40
     * @param string                                $requestedName
41
     * @param array<string, (bool|int|string)>|null $options
42
     * @phpstan-param array{
43
     *     access_token?: string,
44
     *     enabled?: bool,
45
     *     transmit?: bool,
46
     *     log_payload?: bool,
47
     *     verbose?: (Config::VERBOSE_NONE|LogLevel::*),
48
     *     environment?: string,
49
     *     level?: (value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::*),
50
     *     bubble?: bool}|null $options
51
     *
52
     * @throws ServiceNotFoundException   if unable to resolve the service
53
     * @throws ServiceNotCreatedException if an exception is raised when creating a service
54
     *
55
     * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
56
     */
57
    #[Override]
×
58
    public function __invoke(
59
        ContainerInterface $container,
60
        $requestedName,
61
        array | null $options = null,
62
    ): RollbarHandler {
63
        if (!is_array($options)) {
×
64
            throw new ServiceNotCreatedException('Options must be an Array');
×
65
        }
66

67
        if (!array_key_exists('access_token', $options)) {
×
68
            throw new ServiceNotCreatedException('No access token provided');
×
69
        }
70

71
        $token       = $options['access_token'];
×
72
        $enabled     = true;
×
73
        $transmit    = true;
×
74
        $logPayload  = true;
×
75
        $verbose     = Config::VERBOSE_NONE;
×
76
        $level       = LogLevel::DEBUG;
×
77
        $bubble      = true;
×
78
        $environment = 'production';
×
79

80
        if (array_key_exists('enabled', $options)) {
×
81
            $enabled = $options['enabled'];
×
82
        }
83

84
        if (array_key_exists('transmit', $options)) {
×
85
            $transmit = $options['transmit'];
×
86
        }
87

88
        if (array_key_exists('log_payload', $options)) {
×
89
            $logPayload = $options['log_payload'];
×
90
        }
91

92
        if (array_key_exists('verbose', $options)) {
×
93
            $verbose = $options['verbose'];
×
94
        }
95

96
        if (array_key_exists('level', $options)) {
×
97
            $level = $options['level'];
×
98
        }
99

100
        if (array_key_exists('bubble', $options)) {
×
101
            $bubble = $options['bubble'];
×
102
        }
103

104
        if (array_key_exists('environment', $options)) {
×
105
            $environment = $options['environment'];
×
106
        }
107

108
        try {
109
            $rollbarLogger = new RollbarLogger(
×
110
                [
×
111
                    'access_token' => $token,
×
112
                    'enabled' => $enabled,
×
113
                    'environment' => $environment,
×
114
                    'log_payload' => $logPayload,
×
115
                    'transmit' => $transmit,
×
116
                    'verbose' => $verbose,
×
117
                ],
×
118
            );
×
119
        } catch (InvalidArgumentException $e) {
×
120
            throw new ServiceNotCreatedException(
×
121
                sprintf('Could not create service %s', RollbarLogger::class),
×
122
                0,
×
123
                $e,
×
124
            );
×
125
        }
126

127
        $handler = new RollbarHandler($rollbarLogger, $level, $bubble);
×
128

129
        $this->addFormatter($container, $handler, $options);
×
130
        $this->addProcessor($container, $handler, $options);
×
131

132
        return $handler;
×
133
    }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc