GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Menu::getHtmlForMenuItemList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * File holding the abstract Menu class
4
 *
5
 * This file is part of the MediaWiki skin Chameleon.
6
 *
7
 * @copyright 2013 - 2014, Stephan Gambke
8
 * @license   GNU General Public License, version 3 (or any later version)
9
 *
10
 * The Chameleon skin is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by the Free
12
 * Software Foundation, either version 3 of the License, or (at your option) any
13
 * later version.
14
 *
15
 * The Chameleon skin is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU General Public License along
21
 * with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * @file
24
 * @ingroup   Skins
25
 */
26
27
namespace Skins\Chameleon\Menu;
28
29
/**
30
 * Class Menu
31
 *
32
 * @author  Stephan Gambke
33
 * @since   1.0
34
 * @ingroup Skins
35
 */
36
abstract class Menu {
37
38
	private $menuItemFormatter = null;
39
	private $itemListFormatter = null;
40
41
	abstract public function getHtml();
42
43
	/**
44
	 * @param string $href
45
	 * @param string $text
46
	 * @param int    $depth
47
	 * @param string $subitems
48
	 *
49
	 * @return string
50
	 */
51 1
	protected function getHtmlForMenuItem( $href, $text, $depth, $subitems ) {
52 1
		return call_user_func( $this->getMenuItemFormatter(), $href, $text, $depth, $subitems );
53
	}
54
55
	/**
56
	 * @return callable
57
	 */
58
	public function getMenuItemFormatter() {
59
60
		if ( $this->menuItemFormatter === null ) {
61
62
			$this->setMenuItemFormatter( function ( $href, $text, $depth, $subitems ) {
63
				$href = \Sanitizer::cleanUrl( $href );
64
				$text = htmlspecialchars( $text );
65
				$indent = str_repeat( "\t", 2 * $depth );
66
67
				if ( $subitems !== '' ) {
68
					return "$indent<li>\n$indent\t<a href=\"$href\">$text</a>\n$subitems$indent</li>\n";
69
				} else {
70
					return "$indent<li><a href=\"$href\">$text</a></li>\n";
71
				}
72
			} );
73
74
		}
75
76
		return $this->menuItemFormatter;
77
	}
78
79
	/**
80
	 * @param callable $menuItemFormatter
81
	 */
82
	public function setMenuItemFormatter( $menuItemFormatter ) {
83
		$this->menuItemFormatter = $menuItemFormatter;
84
	}
85
86
	/**
87
	 * @param string $rawItemsHtml
88
	 * @param int    $depth
89
	 *
90
	 * @return string
91
	 */
92 1
	protected function getHtmlForMenuItemList( $rawItemsHtml, $depth ) {
93 1
		return call_user_func( $this->getItemListFormatter(), $rawItemsHtml, $depth );
94
	}
95
96
	/**
97
	 * @return callable
98
	 */
99
	public function getItemListFormatter() {
100
101
		if ( $this->itemListFormatter === null ) {
102
			$this->setItemListFormatter( function ( $rawItemsHtml, $depth ) {
103
				$indent = str_repeat( "\t", 2 * $depth + 1 );
104
				return "$indent<ul>\n$rawItemsHtml$indent</ul>\n";
105
			} );
106
		}
107
108
		return $this->itemListFormatter;
109
	}
110
111
	/**
112
	 * @param callable $itemListFormatter
113
	 */
114
	public function setItemListFormatter( $itemListFormatter ) {
115
		$this->itemListFormatter = $itemListFormatter;
116
	}
117
118
}
119