Filter::read()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 0
cts 16
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 * ownCloud - Documents App
5
 *
6
 * @author Victor Dubiniuk
7
 * @copyright 2013 Victor Dubiniuk [email protected]
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later.
11
 */
12
13
namespace OCA\Documents;
14
15
 class Filter {
16
	protected static $filters = array();
17
	 
18
	public static function add($mimetype, $class){
19
		 self::$filters[$mimetype] = $class;
20
	}
21
22 View Code Duplication
	public static function read($content, $mimetype){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
		$data = array(
24
			'mimetype' => $mimetype,
25
			'content' => $content
26
		);
27
28
		if (isset(self::$filters[$mimetype])){
29
			$data = call_user_func(
30
					array(
31
						self::$filters[$mimetype],
32
						'read'
33
					),
34
					$data
35
			);
36
		}
37
		
38
		return $data;
39
	}
40
	 
41 View Code Duplication
	public static function write($content, $mimetype){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
		$data = array(
43
			'mimetype' => $mimetype,
44
			'content' => $content
45
		);
46
		
47
		if (isset(self::$filters[$mimetype])){
48
			$data = call_user_func(
49
					array(
50
						self::$filters[$mimetype],
51
						'write'
52
					),
53
					$data
54
			);
55
		}
56
		
57
		return $data;
58
	}
59
	 
60
	public static function getAll(){
61
		 return array_keys(self::$filters);
62
	}
63
	 
64
	/**
65
	 * Checks if mimetype is supported by the app
66
	 * @param string $mimetype - checked mimetype
67
	 * @return bool
68
	 */
69
	public static function isSupportedMimetype($mimetype){
70
		return in_array($mimetype, Storage::getSupportedMimetypes());
71
	} 
72
}
73
74