Passed
Push — master ( 2dbb0d...2ad290 )
by Xavier
01:17
created

Output::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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