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

SpyingFileFetcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fetchFile() 0 4 1
A getFetchedUrls() 0 3 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