Test Failed
Push — master ( dbca4e...c73643 )
by Jeroen De
04:56
created

NormalRenderer::fileHasExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
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