Passed
Push — master ( 202ca4...c1a033 )
by
unknown
37s
created

SpyingFileFetcher::getFirstFetchedUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 2
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 6
	public function __construct( FileFetcher $fileFetcher ) {
22 6
		$this->fileFetcher = $fileFetcher;
23 6
	}
24
25
	/**
26
	 * @see FileFetcher::fetchFile
27
	 * @throws FileFetchingException
28
	 */
29 4
	public function fetchFile( string $fileUrl ): string {
30 4
		$this->fetchedUrls[] = $fileUrl;
31 4
		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
	 * @since 4.3
45
	 *
46
	 * @return string|null
47
	 */
48 2
	public function getFirstFetchedUrl() {
49 2
		return empty( $this->fetchedUrls ) ? null : $this->fetchedUrls[0];
50
	}
51
52
}
53