MediaWikiFileUrlFinder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 16
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getUrlForFileName() 0 13 4
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\DataAccess;
6
7
use Maps\FileUrlFinder;
8
use RepoGroup;
9
10
/**
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class MediaWikiFileUrlFinder implements FileUrlFinder {
15
16 35
	public function getUrlForFileName( string $fileName ): string {
17 35
		$colonPosition = strpos( $fileName, ':' );
18
19 35
		$titleWithoutPrefix = $colonPosition === false ? $fileName : substr( $fileName, $colonPosition + 1 );
20
21 35
		$file = RepoGroup::singleton()->findFile( trim( $titleWithoutPrefix ) );
22
23 35
		if ( $file && $file->exists() ) {
24
			return $file->getURL();
25
		}
26
27 35
		return trim( $fileName );
28
	}
29
}
30