Completed
Push — stable8.2 ( 09e830...ae9bfd )
by Olivier
12:09
created

Base64Encode::encode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * ownCloud - galleryplus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Olivier Paroz <[email protected]>
9
 *
10
 * @copyright Olivier Paroz 2015
11
 */
12
13
namespace OCA\GalleryPlus\Service;
14
15
/**
16
 * Base64 encoding utility method
17
 *
18
 * @package OCA\GalleryPlus\Service
19
 */
20
trait Base64Encode {
21
22
	/**
23
	 * Returns base64 encoded data of a preview
24
	 *
25
	 * Using base64_encode for files which are downloaded
26
	 * (cached Thumbnails, SVG, GIFs) and using __toStrings
27
	 * for the previews which are instances of \OC_Image
28
	 *
29
	 * @param \OC_Image|string $previewData
30
	 *
31
	 * @return string
32
	 */
33 10
	protected function encode($previewData) {
34 10
		if ($previewData instanceof \OC_Image) {
35 4
			$previewData = (string)$previewData;
36
		} else {
37 6
			$previewData = base64_encode($previewData);
38
		}
39
40 10
		return $previewData;
41
	}
42
}
43