Completed
Pull Request — master (#434)
by Joas
08:12
created

BaseFormatter::format()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0417

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4286
cc 3
eloc 7
nc 3
nop 4
crap 3.0417
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2015, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Activity\Formatter;
23
24
use OCP\Activity\IEvent;
25
use OCP\Util;
26
27
class BaseFormatter implements IFormatter {
28
	/**
29
	 * @param IEvent $event
30
	 * @param string $parameter The parameter to be formatted
31
	 * @param bool $allowHtml   Should HTML be used to format the parameter?
32
	 * @param bool $verbose     Should paths, names, etc be shortened or full length
33
	 * @return string The formatted parameter
34
	 */
35 4
	public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) {
36 4
		if ($allowHtml === null) {
37
			return '<parameter>' . Util::sanitizeHTML($parameter) . '</parameter>';
38
		}
39
40 4
		if ($allowHtml) {
41 2
			return '<strong>' . Util::sanitizeHTML($parameter) . '</strong>';
42
		} else {
43 2
			return $parameter;
44
		}
45
	}
46
}
47