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

fractalzombie / frzb-metrics-power / 8471520240

28 Mar 2024 05:48PM UTC coverage: 85.116% (-4.6%) from 89.706%
8471520240

push

github

fractalzombie
[MetricsPower] Added ContextExtractor for logger

[MetricsPower] Added ContextExtractor for logger

78 of 97 new or added lines in 16 files covered. (80.41%)

1 existing line in 1 file now uncovered.

183 of 215 relevant lines covered (85.12%)

5.65 hits per line

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

54.55
/Logger/ContextExtractor/ExceptionEventContextExtractor.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
7
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
 *
10
 * Copyright (c) 2024 Mykhailo Shtanko fractalzombie@gmail.com
11
 *
12
 * For the full copyright and license information, please view the LICENSE.MD
13
 * file that was distributed with this source code.
14
 */
15

16
namespace FRZB\Component\MetricsPower\Logger\ContextExtractor;
17

18
use FRZB\Component\DependencyInjection\Attribute\AsService;
19
use FRZB\Component\DependencyInjection\Attribute\AsTagged;
20
use FRZB\Component\MetricsPower\Attribute\OptionsInterface;
21
use FRZB\Component\MetricsPower\Helper\ClassHelper;
22
use FRZB\Component\MetricsPower\Logger\Data\Context;
23
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
24

25
/**
26
 * @implements ContextExtractorInterface<ExceptionEvent, OptionsInterface>
27
 */
28
#[AsService, AsTagged(ContextExtractorInterface::class)]
29
class ExceptionEventContextExtractor implements ContextExtractorInterface
30
{
31
    private const MESSAGE = '[MetricsPower] [ERROR] [MESSAGE: Operation failed] [TARGET_CLASS: {target_class}] [EXCEPTION_CLASS: {exception_class}] [EXCEPTION_MESSAGE: {exception_message}]';
32

33
    public function extract(mixed $target, ?OptionsInterface $options = null, ?\Throwable $exception = null): Context
34
    {
35
        $context = [
2✔
36
            'target_class' => ClassHelper::getShortName($target),
2✔
37
        ];
2✔
38

39
        if ($exception) {
2✔
NEW
40
            $context += [
×
NEW
41
                'exception_class' => ClassHelper::getShortName($target->getThrowable()),
×
NEW
42
                'exception_message' => $target->getThrowable()->getMessage(),
×
NEW
43
                'exception_trace' => $target->getThrowable()->getTrace(),
×
NEW
44
            ];
×
45
        }
46

47
        return new Context(self::MESSAGE, $context);
2✔
48
    }
49

50
    public static function getType(): string
51
    {
52
        return ExceptionEvent::class;
4✔
53
    }
54
}
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