Passed
Push — master ( c3bafb...29fa5f )
by Xavier
02:01
created

Output::resetLists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Models;
4
5
use PubPeerFoundation\PublicationDataExtractor\ApiDataChecker;
6
7
class Output extends Model
8
{
9
    /**
10
     * Global content array.
11
     *
12
     * @var array
13
     */
14
    protected $content = [];
15
16
    /**
17
     * Dynamically call the add method on the desired model.
18
     *
19
     * @param string $name
20
     * @param array  $resourceData
21
     */
22
    public function __call($name, array $resourceData): void
23
    {
24
        $name = strtolower(substr($name, 3));
25
26
        if (in_array($name, ApiDataChecker::getDataTypes())) {
27
            $className = __NAMESPACE__.'\\'.ucfirst($name);
28
            $this->content[$name] = $className::getInstance()->add($resourceData[0]);
29
        }
30
    }
31
32
    /**
33
     * Output the formatted content array.
34
     *
35
     * @return array
36
     */
37
    public function format()
38
    {
39
        $this->resetLists();
40
41
        return $this->content;
42
    }
43
44
    protected function resetLists()
45
    {
46
        foreach (ApiDataChecker::getDataTypes() as $type) {
47
            $className = __NAMESPACE__.'\\'.ucfirst($type);
48
            $className::getInstance()->reset();
49
        }
50
    }
51
}
52