Completed
Pull Request — master (#15)
by Jeroen De
18:02 queued 07:37
created

CallbackFileFetcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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 GNU GPL v2+
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
	public function __construct( callable $callback ) {
26
		$this->callback = $callback;
27
	}
28
29
	public function fetchFile( string $fileUrl ): string {
30
		return ($this->callback)( $fileUrl );
31
	}
32
33
}
34