Passed
Push — master ( 2571fd...68bcea )
by Felipe
01:45
created

ExceptionHelper::export()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Felipe Sayão Lobato Abreu <[email protected]>
4
 * @package CoiSA\ErrorHandler\Helper
5
 * @since 2017-07-25
6
 */
7
8
namespace CoiSA\ErrorHandler\Helper;
9
10
use Throwable;
11
12
/**
13
 * Class ExceptionHelper
14
 */
15
class ExceptionHelper
16
{
17
    /**
18
     * @param Throwable $throwable
19
     * @return array
20
     */
21
    public static function toArray(Throwable $throwable): array
22
    {
23
        return [
24
            'class' => get_class($throwable),
25
            'message' => $throwable->getMessage(),
26
            'code' => $throwable->getCode(),
27
            'file' => $throwable->getFile() . ':' . $throwable->getLine(),
28
        ];
29
    }
30
31
    /**
32
     * @param Throwable $throwable
33
     * @param int $options [optional]
34
     * @param int $depth [optional]
35
     * @return string
36
     */
37
    public static function toJson(Throwable $throwable, $options = 0, $depth = 512): string
38
    {
39
        return json_encode(self::toArray($throwable), $options, $depth);
0 ignored issues
show
Unused Code introduced by
The call to json_encode() has too many arguments starting with $depth. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        return /** @scrutinizer ignore-call */ json_encode(self::toArray($throwable), $options, $depth);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
40
    }
41
}