StopwatchFileFetcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
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 29
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 15 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace FileFetcher\Stopwatch\PackagePrivate;
6
7
use FileFetcher\FileFetcher;
8
use FileFetcher\FileFetchingException;
9
use Symfony\Component\Stopwatch\Stopwatch;
10
11
/**
12
 * This class is package private and should not be bound to from outside this library.
13
 *
14
 * @licence BSD-3-Clause
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class StopwatchFileFetcher implements FileFetcher {
18
19
	private $fileFetcher;
20
	private $stopwatch;
21
	private $category;
22
23 5
	public function __construct( FileFetcher $fileFetcher, Stopwatch $stopwatch, string $category ) {
24 5
		$this->fileFetcher = $fileFetcher;
25 5
		$this->stopwatch = $stopwatch;
26 5
		$this->category = $category;
27 5
	}
28
29 5
	public function fetchFile( string $fileUrl ): string {
30 5
		$this->stopwatch->start( $fileUrl, $this->category );
31
32
		try {
33 5
			$fileContent = $this->fileFetcher->fetchFile( $fileUrl );
34
		}
35 1
		catch ( FileFetchingException $ex ) {
36 1
			throw $ex;
37
		}
38 4
		finally {
39 5
			$this->stopwatch->stop( $fileUrl );
40
		}
41
42 4
		return $fileContent;
43
	}
44
45
}
46