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

mimmi20 / monolog-factory / 13473020387

22 Feb 2025 12:45PM UTC coverage: 87.861% (-0.1%) from 87.966%
13473020387

push

github

web-flow
Merge pull request #661 from mimmi20/dependabot/composer/4.x/phpunit/phpunit-tw-12.0.4

composer (4.x)(deps-dev): update phpunit/phpunit requirement from ^11.5.6 to ^12.0.4

2497 of 2842 relevant lines covered (87.86%)

33.38 hits per line

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

86.96
/src/Handler/MandrillHandlerFactory.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\MandrillHandler;
23
use Monolog\Level;
24
use Override;
25
use Psr\Container\ContainerInterface;
26
use Psr\Log\LogLevel;
27
use Swift_Message;
28

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

33
final class MandrillHandlerFactory implements FactoryInterface
34
{
35
    use AddFormatterTrait;
36
    use AddProcessorTrait;
37
    use SwiftMessageTrait;
38

39
    /**
40
     * @param string                                         $requestedName
41
     * @param array<string, (bool|callable|int|string)>|null $options
42
     * @phpstan-param array{message?: (string|Swift_Message|callable(): Swift_Message), apiKey?: string, level?: (value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::*), bubble?: bool}|null $options
43
     *
44
     * @throws ServiceNotFoundException   if unable to resolve the service
45
     * @throws ServiceNotCreatedException if an exception is raised when creating a service
46
     *
47
     * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
48
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
49
     */
50
    #[Override]
24✔
51
    public function __invoke(
52
        ContainerInterface $container,
53
        $requestedName,
54
        array | null $options = null,
55
    ): MandrillHandler {
56
        if (!is_array($options)) {
24✔
57
            throw new ServiceNotCreatedException('Options must be an Array');
4✔
58
        }
59

60
        if (!array_key_exists('apiKey', $options)) {
20✔
61
            throw new ServiceNotCreatedException('No apiKey provided');
4✔
62
        }
63

64
        $message = $this->getSwiftMessage($container, $options['message'] ?? '');
16✔
65

66
        $apiKey = $options['apiKey'];
4✔
67
        $level  = LogLevel::DEBUG;
4✔
68
        $bubble = true;
4✔
69

70
        if (array_key_exists('level', $options)) {
4✔
71
            $level = $options['level'];
4✔
72
        }
73

74
        if (array_key_exists('bubble', $options)) {
4✔
75
            $bubble = $options['bubble'];
4✔
76
        }
77

78
        try {
79
            $handler = new MandrillHandler($apiKey, $message, $level, $bubble);
4✔
80
        } catch (InvalidArgumentException $e) {
4✔
81
            throw new ServiceNotCreatedException(
4✔
82
                sprintf('Could not create %s', MandrillHandler::class),
4✔
83
                0,
4✔
84
                $e,
4✔
85
            );
4✔
86
        }
87

88
        $this->addFormatter($container, $handler, $options);
×
89
        $this->addProcessor($container, $handler, $options);
×
90

91
        return $handler;
×
92
    }
93
}
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