ErrorBuilder   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 12
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createFromException() 0 17 1
1
<?php
2
3
namespace SamuelBednarcik\ElasticAPMAgent\Builder;
4
5
use SamuelBednarcik\ElasticAPMAgent\Events\Error;
6
use SamuelBednarcik\ElasticAPMAgent\Events\ErrorException;
7
8
class ErrorBuilder extends AbstractEventBuilder
9
{
10
    /**
11
     * @param \Exception $exception
12
     * @return Error
13
     * @throws \Exception
14
     */
15
    public static function createFromException(\Exception $exception)
16
    {
17
        $trace = $exception->getTrace();
18
19
        $error = new Error();
20
        $error->setId(self::generateRandomBitsInHex(self::ERROR_ID_SIZE));
21
22
        $errorException = new ErrorException();
23
        $errorException->setCode($exception->getCode());
24
        $errorException->setMessage($exception->getMessage());
25
        $errorException->setType(get_class($exception));
26
        $error->setException($errorException);
27
28
        $error->setTimestamp(intval(round(microtime(true) * 1000000)));
29
        $error->setCulprit($trace[0]['class'] . $trace[0]['type'] . $trace[0]['function']);
30
31
        return $error;
32
    }
33
}
34