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

Base64Encode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 23
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A encode() 0 9 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