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

ConvertsRichtext::convertRichtext()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 8
rs 9.6111
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
}