Filter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 62.07 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 36
loc 58
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A read() 18 18 2
A write() 18 18 2
A getAll() 0 3 1
A isSupportedMimetype() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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