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

FilePrefixer::prefixFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 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
}