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

The-oGlow / ezlogging / 17293970101

28 Aug 2025 11:06AM UTC coverage: 83.249%. First build
17293970101

push

github

ollily
update analysis workflow

29 of 31 new or added lines in 6 files covered. (93.55%)

164 of 197 relevant lines covered (83.25%)

7.29 hits per line

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

87.5
/src/Monolog/Processor/PaddingProcessor.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of ezlogging
7
 *
8
 * (c) 2025 Oliver Glowa, coding.glowa.com
9
 *
10
 * This source file is subject to the Apache-2.0 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace Monolog\Processor;
15

16
use Monolog\Logger;
17

18
/**
19
 * Class PaddingProcessor
20
 *
21
 * Use Introspection from @link IntrospectionProcessor.
22
 *
23
 * @package Monolog\Processor
24
 * @see     IntrospectionProcessor
25
 */
26
class PaddingProcessor implements ProcessorInterface
27
{
28
    /** @var integer */
29
    private $level;
30

31
    /** @var string[] */
32
    private $skipClassesPartials;
33

34
    /** @var int */
35
    private $skipStackFramesCount;
36

37
    /** @var string[] */
38
    private $skipFunctions = [
39
        'call_user_func',
40
        'call_user_func_array'
41
    ];
42

43
    /**
44
     *
45
     * @param mixed    $level
46
     *            The minimum logging level at which this Processor will be triggered
47
     * @param string[] $skipClassesPartials
48
     * @param int      $skipStackFramesCount
49
     */
50
    public function __construct($level = Logger::DEBUG, array $skipClassesPartials = [], int $skipStackFramesCount = 0)
13✔
51
    {
52
        $this->level                = Logger::toMonologLevel($level);
13✔
53
        $this->skipClassesPartials  = array_merge(
13✔
54
            [
13✔
55
                'Monolog\\'
13✔
56
            ],
13✔
57
            $skipClassesPartials
13✔
58
        );
13✔
59
        $this->skipStackFramesCount = $skipStackFramesCount;
13✔
60
    }
61

62
    /**
63
     *
64
     * @param mixed[] $record
65
     *
66
     * @return mixed[]
67
     */
68
    public function __invoke(array $record): array
2✔
69
    {
70
        $record                   = $this->__invokeIntrospection($record);
2✔
71
        $record['level_name_pad'] = str_pad($record['level_name'], 8, ' ', STR_PAD_RIGHT);
2✔
72

73
        return $record;
2✔
74
    }
75

76
    /**
77
     *
78
     * @param mixed[] $record
79
     *
80
     * @return mixed[]
81
     *
82
     * @SuppressWarnings("PHPMD.CamelCaseMethodName")
83
     * @SuppressWarnings("PHPMD.ElseExpression")
84
     *
85
     */
86
    private function __invokeIntrospection(array $record): array // NOSONAR: php:S100
2✔
87
    {
88
        // return if the level is not high enough
89
        if ($record['level'] < $this->level) {
2✔
90
            return $record;
×
91
        }
92

93
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
2✔
94

95
        // skip first since it's always the current method
96
        array_shift($trace);
2✔
97
        // the call_user_func call is also skipped
98
        array_shift($trace);
2✔
99

100
        $index = 0;
2✔
101

102
        while ($this->isTraceClassOrSkippedFunction($trace, $index)) {
2✔
103
            if (isset($trace[$index]['class'])) {
2✔
104
                foreach ($this->skipClassesPartials as $part) {
2✔
105
                    if (strpos($trace[$index]['class'], $part) !== false) {
2✔
106
                        $index++;
2✔
107

108
                        continue 2;
2✔
109
                    }
110
                }
NEW
111
            } elseif (in_array($trace[$index]['function'], $this->skipFunctions, true)) {
×
NEW
112
                $index++;
×
113

114
                continue;
×
115
            } else {
116
                break;
×
117
            }
118
            break;
2✔
119
        }
120

121
        $index += $this->skipStackFramesCount;
2✔
122

123
        // we should have the call source now
124
        if ($index > 0 && $index < count($trace)) {
2✔
125
            $curTrace  = $trace[$index];
2✔
126
            $prevTrace = $trace[$index - 1];
2✔
127
            $xDetails  = [
2✔
128
                'xFile'     => $prevTrace['file'] ?? null,
2✔
129
                'xLine'     => $prevTrace['line'] ?? null,
2✔
130
                'xClass'    => $curTrace['class'] ?? null,
2✔
131
                'xCallType' => $curTrace['type'] ?? null,
2✔
132
                'xFunction' => $curTrace['function']
2✔
133
            ];
2✔
134
            $record    = array_merge($record, $xDetails);
2✔
135
        }
136

137
        return $record;
2✔
138
    }
139

140
    /**
141
     *
142
     * @param mixed[] $trace
143
     * @param int     $index
144
     *
145
     * @return bool
146
     */
147
    private function isTraceClassOrSkippedFunction(array $trace, int $index): bool
2✔
148
    {
149
        if (!isset($trace[$index])) {
2✔
150
            return false;
×
151
        }
152

153
        return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions, true);
2✔
154
    }
155
}
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