|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Konfig |
|
5
|
|
|
* |
|
6
|
|
|
* Yet another simple configuration loader library. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Xeriab Nabil (aka KodeBurner) <[email protected]> |
|
9
|
|
|
* @license https://raw.github.com/xeriab/konfig/master/LICENSE MIT |
|
10
|
|
|
* @link https://xeriab.github.io/projects/konfig |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Exen\Konfig\FileParser; |
|
14
|
|
|
|
|
15
|
|
|
use Exen\Konfig\Utils; |
|
16
|
|
|
use Exen\Konfig\Exception\Exception; |
|
17
|
|
|
use Exen\Konfig\Exception\ParseException; |
|
18
|
|
|
|
|
19
|
|
|
use Nette\Neon\Neon as NeonParser; |
|
20
|
|
|
|
|
21
|
|
|
class Neon extends AbstractFileParser |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
* Loads a NEON file as an array |
|
26
|
|
|
* |
|
27
|
|
|
* @throws ParseException If there is an error parsing NEON file |
|
28
|
6 |
|
* @since 0.1.0 |
|
29
|
|
|
*/ |
|
30
|
6 |
|
public function parse($path) |
|
31
|
|
|
{ |
|
32
|
|
|
$data = null; |
|
33
|
6 |
|
|
|
34
|
5 |
|
try { |
|
35
|
3 |
|
$data = $this->loadFile($path); |
|
36
|
3 |
|
} catch (\Exception $ex) { |
|
37
|
3 |
|
throw new ParseException([ |
|
38
|
3 |
|
'message' => 'Error parsing NEON file', |
|
39
|
2 |
|
'file' => $path, |
|
40
|
2 |
|
'exception' => $ex, |
|
41
|
|
|
]); |
|
42
|
3 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $data; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
3 |
|
* {@inheritDoc} |
|
49
|
|
|
*/ |
|
50
|
3 |
|
public function getSupportedFileExtensions() |
|
51
|
|
|
{ |
|
52
|
|
|
return ['neon']; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Loads in the given file and parses it. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $file File to load |
|
59
|
|
|
* @return array |
|
60
|
|
|
* @since 0.2.4 |
|
61
|
|
|
* @codeCoverageIgnore |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function loadFile($file = null) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->file = $file; |
|
66
|
|
|
$contents = $this->parseVars(Utils::getContent($file)); |
|
67
|
|
|
return NeonParser::decode($contents); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the formatted configuration file contents. |
|
72
|
|
|
* |
|
73
|
|
|
* @param array $content configuration array |
|
|
|
|
|
|
74
|
|
|
* @return string formatted configuration file contents |
|
75
|
|
|
* @since 0.2.4 |
|
76
|
|
|
* @codeCoverageIgnore |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function exportFormat($contents = null) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->prepVars($contents); |
|
|
|
|
|
|
81
|
|
|
return NeonParser::encode($contents); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// END OF ./src/FileParser/Neon.php FILE |
|
86
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.