QuoteTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 51
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
parseBlocks() 0 1 ?
renderAbsy() 0 1 ?
A identifyQuote() 0 4 4
B consumeQuote() 0 25 6
A renderQuote() 0 4 1
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\block;
9
10
/**
11
 * Adds the block quote elements
12
 */
13
trait QuoteTrait
14
{
15
	/**
16
	 * identify a line as the beginning of a block quote.
17
	 */
18 205
	protected function identifyQuote($line)
19
	{
20 205
		return $line[0] === '>' && (!isset($line[1]) || ($l1 = $line[1]) === ' ' || $l1 === "\t");
21
	}
22
23
	/**
24
	 * Consume lines for a blockquote element
25
	 */
26 27
	protected function consumeQuote($lines, $current)
27
	{
28
		// consume until newline
29 27
		$content = [];
30 27
		for ($i = $current, $count = count($lines); $i < $count; $i++) {
31 27
			$line = $lines[$i];
32 27
			if (ltrim($line) !== '') {
33 27
				if ($line[0] == '>' && !isset($line[1])) {
34 8
					$line = '';
35 27
				} elseif (strncmp($line, '> ', 2) === 0) {
36 27
					$line = substr($line, 2);
37
				}
38 27
				$content[] = $line;
39
			} else {
40 24
				break;
41
			}
42
		}
43
44
		$block = [
45 27
			'quote',
46 27
			'content' => $this->parseBlocks($content),
47
			'simple' => true,
48
		];
49 27
		return [$block, $i];
50
	}
51
52
53
	/**
54
	 * Renders a blockquote
55
	 */
56 27
	protected function renderQuote($block)
57
	{
58 27
		return '<blockquote>' . $this->renderAbsy($block['content']) . "</blockquote>\n";
59
	}
60
61
	abstract protected function parseBlocks($lines);
62
	abstract protected function renderAbsy($absy);
63
}
64