StopwatchFileFetcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

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 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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