StopwatchFileFetcher::fetchFile()   A
last analyzed

Complexity

Conditions 2
Paths 6

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.7666
c 0
b 0
f 0
cc 2
nc 6
nop 1
crap 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