Code Duplication    Length = 37-39 lines in 2 locations

src/Handler/SentryMonologHandler.php 1 location

@@ 97-135 (lines=39) @@
94
     * @param  array $record
95
     * @return array
96
     */
97
    private function backtrace($record)
98
    {
99
        // Provided trace
100
        if (!empty($record['context']['trace'])) {
101
            return $record['context']['trace'];
102
        }
103
104
        // Generate trace from exception
105
        if (isset($record['context']['exception'])) {
106
            /** @var Exception $exception */
107
            $exception = $record['context']['exception'];
108
            return $exception->getTrace();
109
        }
110
111
        // Failover: build custom trace
112
        $bt = debug_backtrace();
113
114
        // Push current line into context
115
        array_unshift($bt, [
116
            'file'     => !empty($bt['file']) ? $bt['file'] : 'N/A',
117
            'line'     => !empty($bt['line']) ? $bt['line'] : 'N/A',
118
            'function' => '',
119
            'class'    => '',
120
            'type'     => '',
121
            'args'     => [],
122
        ]);
123
124
        $bt = Backtrace::filter_backtrace($bt, [
125
            '',
126
            'Monolog\\Handler\\AbstractProcessingHandler->handle',
127
            'Monolog\\Logger->addRecord',
128
            'Monolog\\Logger->log',
129
            'Monolog\\Logger->warn',
130
            'PhpTek\\Sentry\\Handler\\SentryMonologHandler->write',
131
            'PhpTek\\Sentry\\Handler\\SentryMonologHandler->backtrace',
132
        ]);
133
134
        return $bt;
135
    }
136
137
    /**
138
     * Returns a default set of additional data specific to the user's part in

src/Log/SentryLogger.php 1 location

@@ 297-333 (lines=37) @@
294
     * @return array
295
     * @todo   Unused in sentry-sdk 2.0??
296
     */
297
    public static function backtrace(array $record) : array
298
    {
299
        // Provided trace
300
        if (!empty($record['context']['trace'])) {
301
            return $record['context']['trace'];
302
        }
303
304
        // Generate trace from exception
305
        if (isset($record['context']['exception'])) {
306
            $exception = $record['context']['exception'];
307
308
            return $exception->getTrace();
309
        }
310
311
        // Failover: build custom trace
312
        $bt = debug_backtrace();
313
314
        // Push current line into context
315
        array_unshift($bt, [
316
            'file'     => !empty($bt['file']) ? $bt['file'] : 'N/A',
317
            'line'     => !empty($bt['line']) ? $bt['line'] : 'N/A',
318
            'function' => '',
319
            'class'    => '',
320
            'type'     => '',
321
            'args'     => [],
322
        ]);
323
324
       return Backtrace::filter_backtrace($bt, [
325
            '',
326
            'Monolog\\Handler\\AbstractProcessingHandler->handle',
327
            'Monolog\\Logger->addRecord',
328
            'Monolog\\Logger->log',
329
            'Monolog\\Logger->warn',
330
            'PhpTek\\Sentry\\Handler\\SentryMonologHandler->write',
331
            'PhpTek\\Sentry\\Handler\\SentryMonologHandler->backtrace',
332
        ]);
333
    }
334
335
}
336