Completed
Push — master ( 7473a9...a1417a )
by Richard
09:24 queued 11s
created

ConvertsMarkdown::convertMarkdown()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 6
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 10
rs 9.6111
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
use League\CommonMark\Converter;
7
use League\CommonMark\DocParser;
8
use League\CommonMark\Environment;
9
use League\CommonMark\HtmlRenderer;
10
use Webuni\CommonMark\TableExtension\TableExtension;
0 ignored issues
show
Bug introduced by
The type Webuni\CommonMark\TableExtension\TableExtension 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...
11
12
trait ConvertsMarkdown
13
{
14
	protected $markdown = [];
15
16
	private function convertMarkdown() {
17
		$environment = Environment::createCommonMarkEnvironment();
18
	//	$environment->addExtension(new TableExtension());
19
20
		$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
21
22
		if ($this->markdown && count($this->markdown)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->markdown 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...
23
			foreach ($this->markdown as $markdown) {
24
				if ($this->content->has($markdown)) {
25
					$this->content[$markdown . '_html'] = $converter->convertToHtml($this->content[$markdown]);
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...
26
				}
27
			}
28
		}
29
	}
30
}