Passed
Push — master ( 792f58...5e1240 )
by Jeroen De
37s
created

SpyingFileFetcher::fetchFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
declare( strict_types=1 );
4
5
namespace FileFetcher;
6
7
/**
8
 * Decorator for FileFetcher objects that records file fetching calls.
9
 *
10
 * @since 3.2
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class SpyingFileFetcher implements FileFetcher {
16
17
	private $fileFetcher;
18
19
	private $fetchedUrls = [];
20
21 4
	public function __construct( FileFetcher $fileFetcher ) {
22 4
		$this->fileFetcher = $fileFetcher;
23 4
	}
24
25
	/**
26
	 * @see FileFetcher::fetchFile
27
	 * @throws FileFetchingException
28
	 */
29 3
	public function fetchFile( string $fileUrl ): string {
30 3
		$this->fetchedUrls[] = $fileUrl;
31 3
		return $this->fileFetcher->fetchFile( $fileUrl );
32
	}
33
34
	/**
35
	 * Returns an ordered list of fetched URLs. Duplicates are preserved.
36
	 *
37
	 * @return string[]
38
	 */
39 3
	public function getFetchedUrls(): array {
40 3
		return $this->fetchedUrls;
41
	}
42
43
}
44