DocNavRecursive::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.439
c 0
b 0
f 0
cc 5
eloc 16
nc 12
nop 1
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/zamm
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/zamm/
11
 */
12
13
namespace Maslosoft\Zamm\Widgets;
14
15
16
use Maslosoft\Staple\Widgets\SubNavRecursive;
17
18
/**
19
 * This widget will display recursive tree of sub pages
20
 * relative to current page.
21
 * @package Maslosoft\Zamm\Widgets
22
 */
23
class DocNavRecursive extends SubNavRecursive
24
{
25
	public $title = '';
26
27
	public function __construct($options = [])
28
	{
29
		if(is_string($options))
30
		{
31
			$this->title = $options;
32
			$options = [];
33
		}
34
		$root = __DIR__;
35
		if(empty($options['root']))
36
		{
37
			$trace = debug_backtrace(null, 1);
38
			$root = dirname($trace[0]['file']);
39
		}
40
		$defaults = [
41
			'root' => $root,
42
			'path' => '.',
43
			'skipLevel' => 1
44
		];
45
		foreach ($defaults as $name => $value)
46
		{
47
			if (!array_key_exists($name, $options))
48
			{
49
				$options[$name] = $value;
50
			}
51
		}
52
		parent::__construct($options);
53
	}
54
55
	public function __toString()
56
	{
57
		$prefix = '';
58
		if($this->title)
59
		{
60
			$prefix = '<h3>' . $this->title . '</h3>' . "\n";
61
		}
62
		return $prefix . parent::__toString() . "\n\n";
63
	}
64
}