Completed
Pull Request — master (#9)
by Jeroen De
06:49 queued 04:26
created

ErrorLoggingFileFetcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fetchFile() 0 14 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace FileFetcher;
6
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\LogLevel;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @author Gabriel Birke < [email protected] >
13
 */
14
class ErrorLoggingFileFetcher implements FileFetcher {
15
16
	private $wrappedFileFetcher;
17
	private $logger;
18
	private $logLevel;
19
20 4
	public function __construct( FileFetcher $fileFetcher, LoggerInterface $logger, string $logLevel = LogLevel::ERROR ) {
21 4
		$this->wrappedFileFetcher = $fileFetcher;
22 4
		$this->logger = $logger;
23 4
		$this->logLevel = $logLevel;
24 4
	}
25
26
	/**
27
	 * @see FileFetcher::fetchFile
28
	 * @throws FileFetchingException
29
	 */
30 4
	public function fetchFile( string $fileUrl ): string {
31
		try {
32 4
			return $this->wrappedFileFetcher->fetchFile( $fileUrl );
33 3
		} catch ( FileFetchingException $e ) {
34 3
			$this->logger->log(
35 3
				$this->logLevel,
36 3
				$e->getMessage(),
37
				[
38 3
					'exception' => $e
39
				]
40
			);
41 3
			throw $e;
42
		}
43
	}
44
45
}
46