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

Authors::add()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Models;
4
5
class Authors extends Model
6
{
7
    /**
8
     * Hold cherry picked list of authors.
9
     *
10
     * @var array
11
     */
12
    protected $list = [];
13
14
    /**
15
     * Add unknown authors to the current list.
16
     *
17
     * @param $authors
18
     * @return array
19
     */
20
    public function add(array $authors): array
21
    {
22
        if (($count = count($authors)) !== ($listCount = count($this->list))) {
23
            if ($count > $listCount) {
24
                return $this->list = $authors;
25
            }
26
27
            return $this->list;
28
        }
29
30
        for ($i = 0; $i < $count; ++$i) {
31
            $this->addUnknownAttributes($authors, $i);
32
        }
33
34
        return $this->list;
35
    }
36
37
    protected function addUnknownAttributes($authors, $i)
38
    {
39
        foreach ($authors[$i] as $key => $value) {
40
            if (empty($value)) {
41
                continue;
42
            }
43
            if (isset($this->list[$i][$key]) && ! empty($this->list[$i][$key])) {
44
                $this->list[$i][$key] = $value;
45
            }
46
        }
47
    }
48
}
49