GitHubParserHook   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 36
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 26 2
1
<?php
2
3
namespace GitHub;
4
5
use ParamProcessor\ProcessingResult;
6
use Parser;
7
use ParserHooks\HookHandler;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class GitHubParserHook implements HookHandler {
14
15
	private $gitHubFetcher;
16
17 10
	public function __construct( GitHubFetcher $gitHubFetcher ) {
18 10
		$this->gitHubFetcher = $gitHubFetcher;
19 10
	}
20
21 10
	public function handle( Parser $parser, ProcessingResult $result ): string {
22 10
		$params = $result->getParameters();
23
24 10
		$content = $this->gitHubFetcher->getFileContent(
25 10
			$params['repo']->getValue(),
26 10
			$params['branch']->getValue(),
27 10
			$params['file']->getValue()
28
		);
29
30 10
		if ( $params['lang']->getValue() === '' ) {
31 9
			return ( new NormalRenderer() )->getRenderedContent( $content, $params['file']->getValue() );
32
		}
33
34 1
		$syntaxRenderer = new SyntaxRenderer(
35
			function( string $syntaxContent ) use ( $parser ) {
36 1
				return $parser->recursiveTagParse( $syntaxContent, null );
37 1
			},
38 1
			$params['lang']->getValue(),
39 1
			$params['line']->getValue(),
40 1
			$params['start']->getValue(),
41 1
			$params['highlight']->getValue(),
42 1
			$params['inline']->getValue()
43
		);
44
45 1
		return $syntaxRenderer->getRenderedContent( $content );
46
	}
47
48
}
49