Completed
Push — master ( b628fb...ab4f5a )
by Jeroen De
13:40 queued 11:32
created

GitHubFetcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFileContent() 0 10 2
A getFileUrl() 0 9 1
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