Passed
Push — master ( b58e9b...f2401b )
by Jeroen De
35s
created

ErrorLoggingFileFetcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
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