ErrorLoggingFileFetcher::fetchFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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 BSD-3-Clause
12
 * @author Gabriel Birke < [email protected] >
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class ErrorLoggingFileFetcher implements FileFetcher {
16
17
	private $wrappedFileFetcher;
18
	private $logger;
19
	private $logLevel;
20
21 4
	public function __construct( FileFetcher $fileFetcher, LoggerInterface $logger, string $logLevel = LogLevel::ERROR ) {
22 4
		$this->wrappedFileFetcher = $fileFetcher;
23 4
		$this->logger = $logger;
24 4
		$this->logLevel = $logLevel;
25 4
	}
26
27
	/**
28
	 * @see FileFetcher::fetchFile
29
	 * @throws FileFetchingException
30
	 */
31 4
	public function fetchFile( string $fileUrl ): string {
32
		try {
33 4
			return $this->wrappedFileFetcher->fetchFile( $fileUrl );
34 3
		} catch ( FileFetchingException $e ) {
35 3
			$this->logger->log(
36 3
				$this->logLevel,
37 3
				$e->getMessage(),
38
				[
39 3
					'exception' => $e
40
				]
41
			);
42 3
			throw $e;
43
		}
44
	}
45
46
}
47