Completed
Push — master ( a52438...bf8826 )
by Henry
06:30
created

includes/Content/Tag/Code.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Content\Tag;
3
4
use Redaxscript\Html;
5
use function array_filter;
6
use function explode;
7
use function htmlspecialchars;
8
use function implode;
9
use function str_replace;
10
11
/**
12
 * children class to parse content for code tags
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category Content
18
 * @author Henry Ruhs
19
 */
20
21
class Code extends TagAbstract
22
{
23
	/**
24
	 * options of the code tag
25
	 *
26
	 * @var array
27
	 */
28
29
	protected array $_optionArray =
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
30
	[
31
		'className' =>
32
		[
33
			'code' => 'rs-js-code rs-code-default'
34
		],
35
		'search' =>
36
		[
37
			'<rs-code>',
38
			'</rs-code>'
39
		],
40
		'delimiter' => '@@@'
41
	];
42
43
	/**
44
	 * process the class
45
	 *
46
	 * @since 3.0.0
47
	 *
48
	 * @param ?string $content content to be parsed
49
	 *
50
	 * @return ?string
51
	 */
52
53 15
	public function process(?string $content = null) : ?string
54
	{
55 15
		$output = str_replace($this->_optionArray['search'], $this->_optionArray['delimiter'], $content);
56 15
		$partArray = array_filter(explode($this->_optionArray['delimiter'], $output));
57
58
		/* html element */
59
60 15
		$preElement = new Html\Element();
61 15
		$preElement->init('pre',
62
		[
63 15
			'class' => $this->_optionArray['className']['code']
64
		]);
65
66
		/* parse as needed */
67
68 15
		foreach ($partArray as $key => $value)
69
		{
70 15
			if ($key % 2)
71
			{
72 3
				$partArray[$key] = $preElement->copy()->html(htmlspecialchars($value, ENT_QUOTES, false, false));
73
			}
74
		}
75 15
		$output = implode($partArray);
76 15
		return $output;
77
	}
78
}
79