MediaWikiFileUrlFinder::getUrlForFileName()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.0466

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
rs 9.8333
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4.0466
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