Passed
Push — master ( 54cf3c...8581d1 )
by Richard
03:45 queued 11s
created

UnableToRenderException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Riclep\Storyblok\Exceptions;
4
5
use Exception;
6
use Facade\IgnitionContracts\Solution;
0 ignored issues
show
Bug introduced by
The type Facade\IgnitionContracts\Solution was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Facade\IgnitionContracts\BaseSolution;
0 ignored issues
show
Bug introduced by
The type Facade\IgnitionContracts\BaseSolution was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Facade\IgnitionContracts\ProvidesSolution;
0 ignored issues
show
Bug introduced by
The type Facade\IgnitionContracts\ProvidesSolution was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Illuminate\Support\Str;
10
use Riclep\Storyblok\Solutions\CreateMissingBlockSolution;
11
12
class UnableToRenderException extends Exception implements ProvidesSolution
13
{
14
	protected $data;
15
16
	public function __construct($message, $data)
17
	{
18
		parent::__construct($message);
19
20
		$this->data = $data;
21
	}
22
23
	/** @return  \Facade\IgnitionContracts\Solution */
24
	public function getSolution(): Solution
25
	{
26
		if (get_class($this->data) === 'App\Storyblok\Block') {
27
			return new CreateMissingBlockSolution($this->data);
28
		}
29
30
		if (count($this->data->_componentPath) === 1) {
31
			if (get_class($this->data) === 'App\Storyblok\Page') {
32
				$title = 'Create a view or custom Page class';
33
				$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 implmenting your own view finding logic.';
34
			} else {
35
				$title = 'Create a view or implement view logic';
36
				$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.';
37
			}
38
		} else {
39
			$title = 'Create a view or implement view logic';
40
			$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.';
41
		}
42
43
		return BaseSolution::create($title)
44
			->setSolutionDescription($description)
45
			->setDocumentationLinks([
46
				'Laravel Storyblok docs' => 'https://ls.sirric.co.uk/docs/',
47
			]);
48
	}
49
50
51
}