MwImageRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 25
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getByName() 0 9 3
A getNameWithoutPrefix() 0 5 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\DataAccess;
6
7
use RepoGroup;
8
9
class MwImageRepository implements ImageRepository {
10
11
	private $repoGroup;
12
13
	public function __construct( RepoGroup $repoGroup ) {
14
		$this->repoGroup = $repoGroup;
15
	}
16
17
	public function getByName( string $imageName ): ?Image {
18
		$file = $this->repoGroup->findFile( trim( $this->getNameWithoutPrefix( $imageName ) ) );
19
20
		if ( $file === false || !$file->exists() ) {
21
			return null;
22
		}
23
24
		return new MwImage( $file );
25
	}
26
27
	private function getNameWithoutPrefix( string $imageName ): string {
28
		$colonPosition = strpos( $imageName, ':' );
29
30
		return $colonPosition === false ? $imageName : substr( $imageName, $colonPosition + 1 );
31
	}
32
33
}
34