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

The-oGlow / ezlogging / 17213505842

25 Aug 2025 03:37PM UTC coverage: 81.865%. Remained the same
17213505842

push

github

ollily
Initial commit

18 of 24 new or added lines in 7 files covered. (75.0%)

12 existing lines in 4 files now uncovered.

158 of 193 relevant lines covered (81.87%)

6.96 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 int */
29
    private $level;
30
    /** @var string[] */
31
    private $skipClassesPartials;
32
    /** @var int */
33
    private $skipStackFramesCount;
34
    /** @var string[] */
35
    private $skipFunctions = [
36
        'call_user_func',
37
        'call_user_func_array'
38
    ];
39

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

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

70
        return $record;
2✔
71
    }
72

73
    /**
74
     *
75
     * @param mixed[] $record
76
     *
77
     * @return mixed[]
78
     */
79
    private function __invokeIntrospection(array $record): array // NOSONAR: php:S100
2✔
80
    {
81
        // return if the level is not high enough
82
        if ($record['level'] < $this->level) {
2✔
UNCOV
83
            return $record;
×
84
        }
85

86
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
2✔
87

88
        // skip first since it's always the current method
89
        array_shift($trace);
2✔
90
        // the call_user_func call is also skipped
91
        array_shift($trace);
2✔
92

93
        $i = 0;
2✔
94

95
        while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
2✔
96
            if (isset($trace[$i]['class'])) {
2✔
97
                foreach ($this->skipClassesPartials as $part) {
2✔
98
                    if (strpos($trace[$i]['class'], $part) !== false) {
2✔
99
                        $i++;
2✔
100

101
                        continue 2;
2✔
102
                    }
103
                }
NEW
104
            } elseif (in_array($trace[$i]['function'], $this->skipFunctions, true)) {
×
UNCOV
105
                $i++;
×
106

107
                continue;
×
108
            } else {
UNCOV
109
                break;
×
110
            }
111
            break;
2✔
112
        }
113

114
        $i += $this->skipStackFramesCount;
2✔
115

116
        // we should have the call source now
117
        if ($i > 0 && $i < count($trace)) {
2✔
118
            $curTrace  = $trace[$i];
2✔
119
            $prevTrace = $trace[$i - 1];
2✔
120
            $xDetails  = [
2✔
121
                'xFile'     => $prevTrace['file'] ?? null,
2✔
122
                'xLine'     => $prevTrace['line'] ?? null,
2✔
123
                'xClass'    => $curTrace['class'] ?? null,
2✔
124
                'xCallType' => $curTrace['type'] ?? null,
2✔
125
                'xFunction' => $curTrace['function']
2✔
126
            ];
2✔
127
            $record    = array_merge($record, $xDetails);
2✔
128
        }
129

130
        return $record;
2✔
131
    }
132

133
    /**
134
     *
135
     * @param mixed[] $trace
136
     * @param int     $index
137
     *
138
     * @return bool
139
     */
140
    private function isTraceClassOrSkippedFunction(array $trace, int $index): bool
2✔
141
    {
142
        if (!isset($trace[$index])) {
2✔
UNCOV
143
            return false;
×
144
        }
145

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