Completed
Push — master ( 14c945...6811c1 )
by Henry
05:37
created

More   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 60
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 28 4
1
<?php
2
namespace Redaxscript\Content\Tag;
3
4
use Redaxscript\Html;
5
use function str_replace;
6
use function strpos;
7
use function substr;
8
9
/**
10
 * children class to parse content for more tags
11
 *
12
 * @since 3.0.0
13
 *
14
 * @package Redaxscript
15
 * @category Content
16
 * @author Henry Ruhs
17
 */
18
19
class More extends TagAbstract
20
{
21
	/**
22
	 * options of the more tag
23
	 *
24
	 * @var array
25
	 */
26
27
	protected $_optionArray =
28
	[
29
		'className' =>
30
		[
31
			'more' => 'rs-link-more'
32
		],
33
		'search' =>
34
		[
35
			'<rs-more>'
36
		]
37
	];
38
39
	/**
40
	 * process the class
41
	 *
42
	 * @since 3.0.0
43
	 *
44
	 * @param string $content content to be parsed
45
	 * @param string $route route of the content
46
	 *
47
	 * @return string
48
	 */
49
50
	public function process(string $content = null, string $route = null) : string
51
	{
52
		$output = str_replace($this->_optionArray['search'], null, $content);
53
		$position = strpos($content, $this->_optionArray['search'][0]);
54
55
		/* html element */
56
57
		$linkElement = new Html\Element();
58
		$linkElement->init('a',
59
		[
60
			'class' => $this->_optionArray['className']['more']
61
		]);
62
63
		/* collect output */
64
65
		if ($position > -1 && $this->_registry->get('lastTable') === 'categories')
66
		{
67
			$output = substr($output, 0, $position);
68
			if ($route)
0 ignored issues
show
Bug Best Practice introduced by
The expression $route of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
69
			{
70
				$output .= $linkElement
71
					->copy()
72
					->attr('href', $this->_registry->get('parameterRoute') . $route)
73
					->text($this->_language->get('read_more'));
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('read_more') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Element::text() does only seem to accept string|integer|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
74
			}
75
		}
76
		return $output;
77
	}
78
}