Passed
Push — master ( 37d5c2...da7383 )
by Richard
03:04 queued 12s
created

ConvertsRichtext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 16
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A initConvertsRichtext() 0 7 4
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
use Storyblok\RichtextRender\Resolver;
7
8
trait ConvertsRichtext
9
{
10
	protected $richtext = [];
11
12
	/**
13
	 * Takes all the fields in $richtext and applies the Storyblok
14
	 * richtext transformer to them. Returns a duplicate field
15
	 * suffixed with _html
16
	 */
17
	public function initConvertsRichtext() {
18
		if (!empty($this->richtext)) {
19
			$richtextResolver = new Resolver();
20
21
			foreach ($this->richtext as $richtextField) {
22
				if ($this->content->has($richtextField)) {
23
					$this->content[$richtextField . '_html'] = $richtextResolver->render($this->content[$richtextField]);
0 ignored issues
show
Bug Best Practice introduced by
The property content does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
				}
25
			}
26
		}
27
	}
28
}