Completed
Push — master ( c82b55...112ae2 )
by Jeroen De
53:00 queued 30:55
created

FilePrefixer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A prefixFile() 0 8 3
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Presentation;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @author Gabriel Birke < [email protected] >
10
 */
11
class FilePrefixer {
12
13
	private $filePrefix;
14
15 91
	public function __construct( string $filePrefix ) {
16 91
		$this->filePrefix = $filePrefix;
17 91
	}
18
19 65
	public function prefixFile( $filename ) {
20 65
		if ( !$this->filePrefix ) {
21 63
			return $filename;
22
		}
23 2
		$pathParts = pathinfo( $filename );
24 2
		$dirPrefix = $pathParts['dirname'] === '.' ? '' : $pathParts['dirname'] . DIRECTORY_SEPARATOR;
25 2
		return $dirPrefix . $this->filePrefix . '.' . $pathParts['basename'];
26
	}
27
28
}