Passed
Push — master ( 0f9932...7bc3f9 )
by Brent
03:42
created

AbstractArrayParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace brendt\stitcher\parser;
4
5
use brendt\stitcher\Config;
6
use brendt\stitcher\factory\ParserFactory;
7
8
abstract class AbstractArrayParser extends AbstractParser {
9
10
    /**
11
     * @var ParserFactory
12
     */
13
    protected $parserFactory;
14
15
    /**
16
     * AbstractParser constructor.
17
     */
18
    public function __construct() {
19
        parent::__construct();
20
21
        $this->parserFactory = Config::getDependency('factory.parser');
22
    }
23
24
    /**
25
     * @param array $data
26
     *
27
     * @return mixed
28
     */
29
    protected function parseArrayData(array $data) {
30
        $result = [];
31
32
        foreach ($data as $id => $entry) {
33
            $result[$id] = $this->parseEntryData($id, $entry);
34
        }
35
36
        return $result;
37
    }
38
39
    protected function parseEntryData($id, $entry) {
40
        foreach ($entry as $field => $value) {
41
            if (is_string($value) && preg_match('/.*\.(md|jpg|png|json|yml)$/', $value) > 0) {
42
                $parser = $this->parserFactory->getParser($value);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $parser is correct as $this->parserFactory->getParser($value) (which targets brendt\stitcher\factory\ParserFactory::getParser()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
44
                if (!$parser) {
45
                    continue;
46
                }
47
48
                $entry[$field] = $parser->parse(trim($value, '/'));
49
            } elseif (is_array($value) && array_key_exists('src', $value)) {
50
                $src = $value['src'];
51
                $parser = $this->parserFactory->getParser($src);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $parser is correct as $this->parserFactory->getParser($src) (which targets brendt\stitcher\factory\ParserFactory::getParser()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
52
53
                if (!$parser) {
54
                    continue;
55
                }
56
57
                $entry[$field] = $parser->parse($value);
58
            }
59
60
            if (!isset($entry['id'])) {
61
                $entry['id'] = $id;
62
            }
63
        }
64
65
        return $entry;
66
    }
67
68
}
69