ErrorLoggingFileFetcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
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 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