Passed
Push — master ( 134a23...4b8ea5 )
by Richard
03:12 queued 10s
created

EmbedsMedia::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
use Embed\Embed;
7
8
trait EmbedsMedia
9
{
10
	/**
11
	 * The Embed\Embed object.
0 ignored issues
show
Bug introduced by
The type Embed\Embed\Embed 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...
12
	 *
13
	 * @var Embed\Embed
14
	 */
15
	private $_embed;
16
17
	/**
18
	 * Initialises the Embed object.
19
	 */
20
	protected function init() {
21
		$this->_embed = Embed::create($this->content);
0 ignored issues
show
Documentation Bug introduced by
It seems like Embed\Embed::create($this->content) of type Embed\Adapters\Adapter is incompatible with the declared type Embed\Embed\Embed of property $_embed.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22
	}
23
24
	/**
25
	 * Returns the embed code looking for a view in storyblok.embeds or the package.
26
	 * If neither are found the raw embed code is returned.
27
	 *
28
	 * @return string
29
	 */
30
	public function html() {
31
		if (method_exists($this, 'embedView')) {
32
			$method = 'embedView';
33
		} else {
34
			$method = 'baseEmbedView';
35
		}
36
37
		if ($this->{$method}()) {
38
			return (string) view($this->{$method}(), [
39
				'embed' => $this->_embed,
40
			]);
41
		}
42
43
		return $this->rawEmbed();
44
	}
45
46
	/**
47
	 * Returns the raw embed code.
48
	 *
49
	 * @return string
50
	 */
51
	public function rawEmbed() {
52
		return $this->_embed->code;
53
	}
54
55
	/**
56
	 * Returns the Embed\Embed object.
57
	 *
58
	 * @return Embed\Embed
59
	 */
60
	public function embed() {
61
		return $this->_embed;
62
	}
63
64
	/**
65
	 * Returns a path to a view to use for embedding this type of media.
66
	 * If the view can not be found it should return false.
67
	 *
68
	 * @return false|string
69
	 */
70
	protected function baseEmbedView() {
71
		if (view()->exists(config('storyblok.view_path') . 'embeds.' . strtolower($this->_embed->providerName))) {
72
			return config('storyblok.view_path') . 'embeds.' . strtolower($this->_embed->providerName);
73
		}
74
75
		if (view()->exists('laravel-storyblok::embeds.' . strtolower($this->_embed->providerName))) {
76
			return 'laravel-storyblok::embeds.' . strtolower($this->_embed->providerName);
77
		}
78
79
		return false;
80
	}
81
82
83
	/**
84
	 * Returns the embed code
85
	 *
86
	 * @return string
87
	 */
88
	public function __toString()
89
	{
90
		return $this->html();
91
	}
92
}