NormalRenderer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 29
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRenderedContent() 0 4 1
A getUnpurifiedRenderedContent() 0 7 2
A isMarkdownFile() 0 4 2
A fileHasExtension() 0 3 1
A renderAsMarkdown() 0 3 1
1
<?php
2
3
namespace GitHub;
4
5
use Michelf\Markdown;
6
7
/**
8
 * @licence GNU GPL v2+
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
class NormalRenderer {
12
13
	public function getRenderedContent( string $content, string $fileName ): string {
14
		return ( new ContentPurifier() )
15
			->purify( $this->getUnpurifiedRenderedContent( $content, $fileName ) );
16
	}
17
18
	private function getUnpurifiedRenderedContent( string $content, string $fileName ): string {
19
		if ( $this->isMarkdownFile( $fileName ) ) {
20
			return $this->renderAsMarkdown( $content );
21
		}
22
23
		return $content;
24
	}
25
26
	private function isMarkdownFile( string $fileName ): bool {
27
		return $this->fileHasExtension( $fileName, '.md' )
28
			|| $this->fileHasExtension( $fileName,'.markdown' );
29
	}
30
31
	private function fileHasExtension( string $fileName, string $extension ): bool {
32
		return substr( $fileName, -strlen( $extension ) ) === $extension;
33
	}
34
35
	private function renderAsMarkdown( string $content ): string {
36
		return Markdown::defaultTransform( $content );
37
	}
38
39
}
40