SolutionTransformer::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 4
nc 8
nop 0
1
<?php
2
3
namespace Facade\Ignition\Solutions;
4
5
use Facade\IgnitionContracts\RunnableSolution;
6
use Facade\IgnitionContracts\Solution;
7
use Illuminate\Contracts\Support\Arrayable;
8
use Throwable;
9
10
class SolutionTransformer implements Arrayable
11
{
12
    /** @var \Facade\IgnitionContracts\Solution */
13
    protected $solution;
14
15
    public function __construct(Solution $solution)
16
    {
17
        $this->solution = $solution;
18
    }
19
20
    public function toArray(): array
21
    {
22
        $isRunnable = ($this->solution instanceof RunnableSolution);
23
24
        return [
25
            'class' => get_class($this->solution),
26
            'title' => $this->solution->getSolutionTitle(),
27
            'description' => $this->solution->getSolutionDescription(),
28
            'links' => $this->solution->getDocumentationLinks(),
29
            'is_runnable' => $isRunnable,
30
            'run_button_text' => $isRunnable ? $this->solution->getRunButtonText() : '',
31
            'run_parameters' => $isRunnable ? $this->solution->getRunParameters() : [],
32
            'action_description' => $isRunnable ? $this->solution->getSolutionActionDescription() : '',
33
            'execute_endpoint' => $this->executeEndpoint(),
34
        ];
35
    }
36
37
    protected function executeEndpoint(): string
38
    {
39
        try {
40
            return action('\Facade\Ignition\Http\Controllers\ExecuteSolutionController');
41
        } catch (Throwable $exception) {
42
            return '';
43
        }
44
    }
45
}
46