CodeTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 51.52 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 17
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseInlineCode() 17 21 3
A renderInlineCode() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @copyright Copyright (c) 2014 Carsten Brandt
4
 * @license https://github.com/cebe/markdown/blob/master/LICENSE
5
 * @link https://github.com/cebe/markdown#readme
6
 */
7
8
namespace cebe\markdown\inline;
9
10
/**
11
 * Adds inline code elements
12
 */
13
trait CodeTrait
14
{
15
	/**
16
	 * Parses an inline code span `` ` ``.
17
	 * @marker `
18
	 */
19 32
	protected function parseInlineCode($text)
20
	{
21 32 View Code Duplication
		if (preg_match('/^(``+)\s(.+?)\s\1/s', $text, $matches)) { // code with enclosed backtick
22
			return [
23
				[
24 9
					'inlineCode',
25 9
					$matches[2],
26
				],
27 9
				strlen($matches[0])
28
			];
29 32
		} elseif (preg_match('/^`(.+?)`/s', $text, $matches)) {
30
			return [
31
				[
32 32
					'inlineCode',
33 32
					$matches[1],
34
				],
35 32
				strlen($matches[0])
36
			];
37
		}
38 4
		return [['text', $text[0]], 1];
39
	}
40
41 32
	protected function renderInlineCode($block)
42
	{
43 32
		return '<code>' . htmlspecialchars($block[1], ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</code>';
44
	}
45
}
46