SolutionTransformer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 16 4
A executeEndpoint() 0 8 2
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