Completed
Push — master ( 8dce14...ef59ee )
by Freek
13:50
created

ErrorPageHandler::handleReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Facade\Ignition\ErrorPage;
4
5
use Throwable;
6
use Facade\FlareClient\Report;
7
use Facade\Ignition\IgnitionConfig;
8
use Illuminate\Foundation\Application;
9
use Facade\IgnitionContracts\SolutionProviderRepository;
10
11
class ErrorPageHandler
12
{
13
    /** @var \Facade\Ignition\IgnitionConfig */
14
    protected $ignitionConfig;
15
16
    /** @var \Facade\Ignition\Facades\Flare */
17
    protected $flareClient;
18
19
    /** @var \Facade\Ignition\ErrorPage\Renderer */
20
    protected $renderer;
21
22
    /** @var \Facade\IgnitionContracts\SolutionProviderRepository */
23
    protected $solutionProviderRepository;
24
25
    public function __construct(
26
        Application $app,
27
        IgnitionConfig $ignitionConfig,
28
        Renderer $renderer,
29
        SolutionProviderRepository $solutionProviderRepository
30
    ) {
31
        $this->flareClient = $app->make('flare.client');
32
        $this->ignitionConfig = $ignitionConfig;
33
        $this->renderer = $renderer;
34
        $this->solutionProviderRepository = $solutionProviderRepository;
35
    }
36
37
    public function handle(Throwable $throwable, $defaultTab = null, $defaultTabProps = [])
38
    {
39
        $report = $this->flareClient->createReport($throwable);
0 ignored issues
show
Bug introduced by
The method createReport() does not seem to exist on object<Facade\Ignition\Facades\Flare>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        $solutions = $this->solutionProviderRepository->getSolutionsForThrowable($throwable);
42
43
        $viewModel = new ErrorPageViewModel(
44
            $throwable,
45
            $this->ignitionConfig,
46
            $report,
47
            $solutions
48
        );
49
50
        $viewModel->defaultTab($defaultTab, $defaultTabProps);
51
52
        $this->renderException($viewModel);
53
    }
54
55
    public function handleReport(Report $report, $defaultTab = null, $defaultTabProps = [])
56
    {
57
        $viewModel = new ErrorPageViewModel(
58
            $report->getThrowable(),
59
            $this->ignitionConfig,
60
            $report,
61
            []
62
        );
63
64
        $viewModel->defaultTab($defaultTab, $defaultTabProps);
65
66
        $this->renderException($viewModel);
67
    }
68
69
    protected function renderException(ErrorPageViewModel $exceptionViewModel)
70
    {
71
        echo $this->renderer->render(
72
            'errorPage',
73
            $exceptionViewModel->toArray()
74
        );
75
    }
76
}
77