Test Failed
Push — extract ( e8a5db )
by Jeroen De
05:13 queued 18s
created

GitHubFetcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace GitHub;
4
5
use FileFetcher\FileFetcher;
6
use FileFetcher\FileFetchingException;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class GitHubFetcher {
13
14
	private $fileFetcher;
15
	private $gitHubUrl;
16
17
	public function __construct( FileFetcher $fileFetcher, string $gitHubUrl ) {
18
		$this->fileFetcher = $fileFetcher;
19
		$this->gitHubUrl = $gitHubUrl;
20
	}
21
22
	public function getFileContent( string $repoName, string $branchName, string $fileName ): string {
23
		$url = $this->getFileUrl( $repoName, $branchName, $fileName );
24
25
		try {
26
			return $this->fileFetcher->fetchFile( $url );
27
		}
28
		catch ( FileFetchingException $ex ) {
29
			return '';
30
		}
31
	}
32
33
	private function getFileUrl( string $repoName, string $branchName, string $fileName ): string {
34
		return sprintf(
35
			'%s/%s/%s/%s',
36
			$this->gitHubUrl,
37
			$repoName,
38
			$branchName,
39
			$fileName
40
		);
41
	}
42
43
}
44