AbstractConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B convert() 0 14 5
convertFromDocumentInstance() 0 1 ?
1
<?php
2
3
namespace OpenMindParser\Converters\Model;
4
5
use OpenMindParser\Models\Document;
6
use OpenMindParser\Parser;
7
use \InvalidArgumentException;
8
9
/*Abstract singleton to help write converters.*/
10
abstract class AbstractConverter implements ConverterInterface
11
{
12
	/**
13
	 * The method of the interface ConverterInterface. If the given data is a string and therefore a file path, A Document instance is created. 
14
	 * In the end, the Document instance is converted.
15
	 * 
16
	 * @param mixed $data : The data to convert. Here : a string as the file path or the Document instance.
17
	 * @param array $options = [] : An array of options for the conversion.
18
	 * 
19
	 * @return mixed : The result of the conversion.
20
	 */
21
	public function convert($data, $options = []) {
22
		if(!is_string($data) && !($data instanceof Document)) {
23
			throw new InvalidArgumentException('The $data variable must be of type "string" (the file path), or an instance of "Document".');
24
		} elseif(!is_array($options)) {
25
			throw new InvalidArgumentException('The $options variable must be and array.');
26
		}
27
		
28
		if(is_string($data)) {
29
			$parser = new Parser();
30
			$data = $parser->buildDocumentTreeFromFilePath($data);	
31
		}
32
		
33
		return $this->convertFromDocumentInstance($data, $options);
34
	}
35
	
36
	/**
37
	 * Abstract class to actually perform the conversion from the Document instance passed in parameter.
38
	 * 
39
	 * @param mixed $data : The data to convert. Here : a string as the file path or the Document instance.
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
	 * @param array $options : An array of options for the conversion.
41
	 * 
42
	 * @return mixed : The result of the conversion.
43
	 */
44
	abstract protected function convertFromDocumentInstance(Document $document, array $options);
45
}