UnableToRenderException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSolution() 0 23 4
1
<?php
2
3
namespace Riclep\Storyblok\Exceptions;
4
5
use Exception;
6
use Spatie\Ignition\Contracts\Solution;
7
use Spatie\Ignition\Contracts\BaseSolution;
8
use Spatie\Ignition\Contracts\ProvidesSolution;
9
use Illuminate\Support\Str;
10
use Riclep\Storyblok\Solutions\CreateMissingBlockSolution;
11
12
class UnableToRenderException extends Exception implements ProvidesSolution
13
{
14
15
	public function __construct($message, protected $data)
16
	{
17
		parent::__construct($message);
18
	}
19
20
	/** @return  \Spatie\Ignition\Contracts\Solution */
21
	public function getSolution(): Solution
22
	{
23
		if (get_class($this->data) === 'App\Storyblok\Block') {
24
			return new CreateMissingBlockSolution($this->data);
25
		}
26
27
		if (count($this->data->_componentPath) === 1) {
28
			if (get_class($this->data) === 'App\Storyblok\Page') {
29
				$title = 'Create a view or custom Page class';
30
				$description = 'Create one of the following views: `[' . implode(', ', $this->data->views()) . ']` or a create Page class called `App\Storyblok\Pages\\' . Str::studly($this->data->block()->component()) . '` and override the `views()` method implementing your own view finding logic.';
31
			} else {
32
				$title = 'Create a view or implement view logic';
33
				$description = 'Create one of the following views: `[' . implode(', ', $this->data->views()) . ']` or override the `views()` method in `App\Storyblok\Pages\\' . Str::studly($this->data->block()->component()) . '` and implement your own view finding logic.';
34
			}
35
		} else {
36
			$title = 'Create a view or implement view logic';
37
			$description = 'Create one of the following views: `[' . implode(', ', $this->data->views()) . ']` or override the `views()` method in `App\Storyblok\Blocks\\' . Str::studly($this->data->meta()['component']) . '` and implement your own view finding logic.';
38
		}
39
40
		return BaseSolution::create($title)
41
			->setSolutionDescription($description)
42
			->setDocumentationLinks([
43
				'Laravel Storyblok docs' => 'https://ls.sirric.co.uk/docs/',
44
			]);
45
	}
46
47
48
}