Passed
Push — development ( e7eb97...e615e2 )
by Spuds
01:30 queued 23s
created

Board   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 25
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D generate() 0 17 10
1
<?php
2
3
/**
4
 * Semantic representation of board URLs
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * @version 2.0 dev
11
 *
12
 */
13
14
namespace ElkArte\UrlGenerator\Semantic;
15
16
class Board extends Standard
17
{
18
	/** {@inheritDoc} */
19
	protected $_types = ['board'];
20
21
	/**
22
	 * {@inheritDoc}
23
	 */
24
	public function generate($params)
25
	{
26
		// Safely build a slug from the board name; guard against null
27
		$name = isset($params['name']) && $params['name'] !== null ? (string) $params['name'] : '';
28
		$name = trim($name);
29
		$slug = $name === '' ? 'board' : preg_replace('~\s+~u', '-', $name);
30
		$slug = trim($slug, '-');
31
32
		$board_id = isset($params['board']) ? (int) $params['board'] : 0;
33
		$has_start = isset($params['start']) && $params['start'] !== '' && $params['start'] !== null;
34
		$start = $has_start ? (int) $params['start'] : null;
35
36
		// Semantic pagination format is dot-appended after the id (e.g., b/slug-id.10)
37
		$url = 'b/' . rawurlencode($slug) . '-' . $board_id . ($has_start && $start !== 0 ? '.' . $start : '');
38
		unset($params['name'], $params['board'], $params['start']);
39
40
		return $url . $this->generateQuery($params);
41
	}
42
}
43