Office::write()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * ownCloud - Documents App
5
 *
6
 * @author Victor Dubiniuk
7
 * @copyright 2014 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\Filter;
14
15
class Office {
16
	const NATIVE_MIMETYPE = 'application/vnd.oasis.opendocument.text';
17
	
18
	private $readSpec;
19
	private $writeSpec;
20
	
21
	/* sample mimespec 	
22
			array (
23
				'read' => 
24
					array (
25
						'target' => 'application/vnd.oasis.opendocument.text',
26
						'format' => 'odt:writer8',
27
						'extension' => 'odt'
28
					),
29
				'write' => 
30
					array (
31
						'target' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
32
						'format' => 'docx',
33
						'extension' => 'docx'
34
					)
35
			);
36
37
			array(
38
				'read' => 
39
					array (
40
						'target' => 'application/vnd.oasis.opendocument.text',
41
						'format' => 'odt:writer8',
42
						'extension' => 'odt'
43
					),
44
				'write' => 
45
					array (
46
						'target' => 'application/msword',
47
						'format' => 'doc',
48
						'extension' => 'doc'
49
					)
50
			);
51
52
		 */
53
	
54
	public function __construct($mimeSpec){
55
		$this->readSpec = $mimeSpec['read'];
56
		$this->writeSpec = $mimeSpec['write'];
57
		
58
		\OCA\Documents\Filter::add($mimeSpec['write']['target'], $this);
59
	}
60
61 View Code Duplication
	public function read($data){
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...
62
		return array(
63
			'mimetype' => $this->readSpec['target'],
64
			'content' => 
65
				\OCA\Documents\Converter::convert(
66
						$data['content'], 
67
						$this->readSpec['format'],
68
						$this->readSpec['extension']
69
				)
70
		);
71
	}
72
	
73 View Code Duplication
	public function write($data){
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...
74
		return array(
75
			'mimetype' => $this->writeSpec['target'],
76
			'content' => 
77
				\OCA\Documents\Converter::convert(
78
						$data['content'], 
79
						$this->writeSpec['format'],
80
						$this->writeSpec['extension']
81
				)
82
		);
83
	}
84
85
}
86