ExecuteSolutionRequest::getSolution()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Facade\Ignition\Http\Requests;
4
5
use Facade\IgnitionContracts\RunnableSolution;
6
use Facade\IgnitionContracts\Solution;
7
use Facade\IgnitionContracts\SolutionProviderRepository;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class ExecuteSolutionRequest extends FormRequest
11
{
12
    public function rules(): array
13
    {
14
        return [
15
            'solution' => 'required',
16
            'parameters' => 'array',
17
        ];
18
    }
19
20
    public function getSolution(): Solution
21
    {
22
        $solution = app(SolutionProviderRepository::class)
23
            ->getSolutionForClass($this->get('solution'));
24
25
        abort_if(is_null($solution), 404, 'Solution could not be found');
26
27
        return $solution;
28
    }
29
30
    public function getRunnableSolution(): RunnableSolution
31
    {
32
        $solution = $this->getSolution();
33
34
        if (! $solution instanceof RunnableSolution) {
35
            abort(404, 'Runnable solution could not be found');
36
        }
37
38
        return $solution;
39
    }
40
}
41