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

Board::generate()   D

Complexity

Conditions 10
Paths 384

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
eloc 10
nc 384
nop 1
dl 0
loc 17
ccs 0
cts 6
cp 0
crap 110
rs 4.5333
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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