Completed
Branch master (8f7741)
by
unknown
02:56
created

Title::render()   B

↳ Parent: Title

Complexity

Conditions 5
Paths 16

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 21
Code Lines 12

Code Coverage

Tests 3
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 3
cts 3
cp 1
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 12
nc 16
nop 0
crap 5
1
<?php
2
namespace Redaxscript\Head;
3
4
use Redaxscript\Db;
5
use Redaxscript\Html;
6
use Redaxscript\Registry;
7
8
/**
9
 * children class to create the title tag
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Head
15
 * @author Henry Ruhs
16
 * @author Balázs Szilágyi
17
 */
18
19
class Title implements HeadInterface
20
{
21
	/**
22
	 * instance of the registry class
23
	 *
24
	 * @var object
25
	 */
26
27
	protected $_registry;
28
29
	/**
30
	 * constructor of the class
31
	 *
32
	 * @since 3.0.0
33
	 *
34
	 * @param Registry $registry instance of the registry class
35
	 */
36
37 4
	public function __construct(Registry $registry)
38
	{
39 4
		$this->_registry = $registry;
40 4
	}
41
42
	/**
43
	 * stringify the title
44
	 *
45
	 * @since 3.0.0
46
	 *
47
	 * @return string
48
	 */
49
50 3
	public function __toString()
51
	{
52 3
		$render = $this->render();
53
		if ($render)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $render of type string|null 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...
54
		{
55
			return $render;
56
		}
57
		return '<!-- Redaxscript\Head\Title -->';
58
	}
59
60
	/**
61
	 * render the title
62
	 *
63 4
	 * @since 3.0.0
64
	 *
65 4
	 * @return string
66 4
	 */
67 4
68
	public function render()
69 4
	{
70 4
		$titleArray =
71 4
		[
72
			'title' => $this->_registry->get('metaTitle') ? $this->_registry->get('metaTitle') : Db::getSetting('title'),
73
			'description' => $this->_registry->get('metaDescription') ? $this->_registry->get('metaDescription') : Db::getSetting('description')
74
		];
75
		$divider = $this->_registry->get('metaDivider') ? $this->_registry->get('metaDivider') : Db::getSetting('divider');
76
77
		/* html elements */
78
79
		$titleElement = new Html\Element();
80
		$titleText = implode($divider, array_filter($titleArray));
81
		if ($titleText)
82
		{
83
			return $titleElement
84
				->init('title')
85
				->text($titleText)
86
				->render();
87
		}
88
	}
89
}