Passed
Push — master ( df8df0...79124a )
by Milan
07:07
created

Utils::extension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace h4kuna\Upload;
4
5
use h4kuna\Upload\Upload\ContentTypeFilter,
6
	Nette\Forms\Controls\UploadControl,
7
	Nette\Forms\Form,
8
	Nette\Http;
9
10
class Utils
11
{
12
13
	/**
14
	 * @param string|IStoreFile $relativePath
15
	 * @return string
16
	 */
17
	public static function makeRelativePath($relativePath)
18
	{
19
		if ($relativePath instanceof IStoreFile) {
20
			return $relativePath->getRelativePath();
21
		}
22
23
		return $relativePath;
24
	}
25
26
27
	/**
28
	 * @param Http\FileUpload $fileUpload
29
	 * @return string|null
30
	 */
31
	public static function extension(Http\FileUpload $fileUpload)
32
	{
33
		return pathinfo($fileUpload->getName(), PATHINFO_EXTENSION);
34
	}
35
36
37
	/**
38
	 * @param ContentTypeFilter $contentTypeFilter
39
	 * @param UploadControl $uploadControl
40
	 * @param string $message
41
	 * @return UploadControl
42
	 */
43
	public static function setMimeTypeRule(ContentTypeFilter $contentTypeFilter, UploadControl $uploadControl, $message)
44
	{
45
		$uploadControl->addRule(Form::MIME_TYPE, $message, $contentTypeFilter->getValues());
46
		return $uploadControl;
47
	}
48
}