|
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. |
|
|
|
|
|
|
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
|
|
|
} |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.