CallbackFileFetcher   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 19
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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