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

mimmi20 / monolog-factory / 13473020985

22 Feb 2025 12:45PM UTC coverage: 87.553% (-0.1%) from 87.658%
13473020985

push

github

web-flow
Merge pull request #668 from mimmi20/dependabot/composer/master/phpunit/phpunit-tw-12.0.4

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

2497 of 2852 relevant lines covered (87.55%)

33.27 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 array<string, (bool|callable|int|string)>|null $options
41
     * @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
42
     *
43
     * @throws ServiceNotFoundException   if unable to resolve the service
44
     * @throws ServiceNotCreatedException if an exception is raised when creating a service
45
     *
46
     * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
47
     */
48
    #[Override]
24✔
49
    public function __invoke(
50
        ContainerInterface $container,
51
        string $requestedName,
52
        array | null $options = null,
53
    ): MandrillHandler {
54
        if (!is_array($options)) {
24✔
55
            throw new ServiceNotCreatedException('Options must be an Array');
4✔
56
        }
57

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

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

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

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

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

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

86
        $this->addFormatter($container, $handler, $options);
×
87
        $this->addProcessor($container, $handler, $options);
×
88

89
        return $handler;
×
90
    }
91
}
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