Completed
Push — master ( 8d39d6...58e1d9 )
by Xeriab
02:50
created

Neon::exportFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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
0 ignored issues
show
Documentation introduced by
There is no parameter named $content. Did you maybe mean $contents?

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 $ireland is not defined by the method finale(...).

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

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

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like $contents defined by parameter $contents on line 78 can also be of type null; however, Exen\Konfig\FileParser\A...tFileParser::prepVars() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
81
        return NeonParser::encode($contents);
82
    }
83
}
84
85
// END OF ./src/FileParser/Neon.php FILE
86