CallbackFileFetcher::fetchFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace FileFetcher;
6
7
/**
8
 * Callback adapter. Calls to fetchFile are routed to the callback.
9
 *
10
 * @since 4.4
11
 *
12
 * @licence BSD-3-Clause
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class CallbackFileFetcher implements FileFetcher {
16
17
	private $callback;
18
19
	/**
20
	 * The callback should have the same signature and contract as @see FileFetcher::fetchFile()
21
	 * Note that this contract include not throwing exceptions other than FileFetchingException.
22
	 *
23
	 * @param callable $callback
24
	 */
25 2
	public function __construct( callable $callback ) {
26 2
		$this->callback = $callback;
27 2
	}
28
29 2
	public function fetchFile( string $fileUrl ): string {
30 2
		return ($this->callback)( $fileUrl );
31
	}
32
33
}
34