GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1)
by Pascal
03:02 queued 27s
created

ErrorResourceBuilder::doNotTraceStack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Saikootau\ApiBundle\Resource\Builder;
6
7
use Saikootau\ApiBundle\Resource\Error;
8
use Throwable;
9
use ReflectionClass;
10
use ReflectionException;
11
12
class ErrorResourceBuilder
13
{
14
    private $traceStack = true;
15
16
    /**
17
     * Trace the whole exception stack.
18
     *
19
     * @return ErrorResourceBuilder
20
     */
21 1
    public function traceStack(): self
22
    {
23 1
        $this->traceStack = true;
24
25 1
        return $this;
26
    }
27
28
    /**
29
     * Only evaluate the topmost exception in stack.
30
     *
31
     * @return ErrorResourceBuilder
32
     */
33 1
    public function doNotTraceStack(): self
34
    {
35 1
        $this->traceStack = false;
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * Build an error resource from an exception.
42
     *
43
     * @param Throwable $exception
44
     *
45
     * @throws ReflectionException
46
     *
47
     * @return Error[]
48
     */
49 10
    public function build(Throwable $exception): array
50
    {
51 10
        $errors = [];
52
53 10
        $errors[] = $this->createError($exception);
54 10
        if ($this->traceStack && $exception->getPrevious()) {
55 1
            $errors = array_merge($errors, $this->build($exception->getPrevious()));
56
        }
57
58 10
        return $errors;
59
    }
60
61
    /**
62
     * Create an error from an exception.
63
     *
64
     * @param Throwable $exception
65
     *
66
     * @throws ReflectionException
67
     *
68
     * @return Error
69
     */
70 10
    private function createError(Throwable $exception): Error
71
    {
72 10
        $reflection = new ReflectionClass($exception);
73
74 10
        return new Error($reflection->getShortName(), $exception->getMessage(), (string) $exception->getCode());
75
    }
76
}
77