Completed
Push — 15.x ( a8a0e5...d73106 )
by Tim
01:34
created

JsonParser::parse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Configuration\Jms\Parsers\JsonParser
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2019 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-configuration-jms
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Configuration\Jms\Parsers;
22
23
use TechDivision\Import\Configuration\Jms\ConfigurationParserInterface;
24
25
/**
26
 * The JSON configuration parser implementation.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2019 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-configuration-jms
32
 * @link      http://www.techdivision.com
33
 */
34
class JsonParser implements ConfigurationParserInterface
35
{
36
37
    /**
38
     * Parsing the configuration and merge it recursively.
39
     *
40
     * @param array  $directories An array with diretories to parse
41
     * @param string $format      The format of the configuration data, either one of json, yaml or xml
0 ignored issues
show
Bug introduced by
There is no parameter named $format. 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...
42
     *
43
     * @return void
44
     */
45
    public function parse(array $directories)
46
    {
47
48
        $main = array();
49
50
        foreach ($directories as $directory) {
51
52
            $directory = new \RecursiveDirectoryIterator($directory);
53
            $iterator = new \RecursiveIteratorIterator($directory);
54
            $regex = new \RegexIterator($iterator, '/^.+\.json$/i', \RecursiveRegexIterator::GET_MATCH);
55
56
            $filenames = array_keys(iterator_to_array($regex));
57
58
            foreach ($filenames as $filename) {
59
60
                if ($content = json_decode(file_get_contents($filename), true)) {
61
                    $main = array_merge_recursive($main, $content);
62
                } else {
63
                    error_log(sprintf('Can\'t load content of file %s', $filename));
64
                }
65
            }
66
        }
67
68
        return json_encode($main, JSON_PRETTY_PRINT);
69
    }
70
}
71