Completed
Push — master ( c6ad08...2b5e21 )
by Richard
05:01 queued 11s
created

AutoParagraphs::autoParagraph()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
trait AutoParagraphs
7
{
8
	protected $autoParagraphs = [];
9
10
	private function autoParagraphs() {
11
		if ($this->autoParagraphs && count($this->autoParagraphs)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->autoParagraphs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
12
			foreach ($this->autoParagraphs as $field) {
13
				if ($this->content->has($field)) {
14
					$this->content[$field . '_html'] = $this->autoParagraph($this->content[$field]);
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...
15
				}
16
			}
17
		}
18
	}
19
20
	private function autoParagraph($text) {
21
		$paragraphs = explode("\n", $text);
22
		return '<p>' . implode('</p><p>', array_filter($paragraphs)) . '</p>';
23
	}
24
}