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

mimmi20 / monolog-factory / 13100304331

02 Feb 2025 03:53PM UTC coverage: 87.658% (-0.3%) from 87.966%
13100304331

push

github

web-flow
Merge pull request #639 from mimmi20/updates

use laminas/laminas-servicemanager 4.3

13 of 23 new or added lines in 13 files covered. (56.52%)

2 existing lines in 2 files now uncovered.

2500 of 2852 relevant lines covered (87.66%)

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

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

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

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

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

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

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

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

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

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

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

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

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

131
        return $handler;
×
132
    }
133
}
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