Passed
Push — master ( 3c2313...4dddea )
by Xavier
12:05
created

Links::isPreprint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Models;
4
5
class Links extends Model
6
{
7
    /**
8
     * Hold cherry picked list of links.
9
     *
10
     * @var array
11
     */
12
    protected $list = [];
13
14
    /**
15
     * Add unknown links to the current list.
16
     */
17
    public function add(array $links): array
18
    {
19
        foreach ($links as $link) {
20
            if ($this->hasPreprint($link)) {
21
                $this->list[] = $link;
22
            }
23
            if ($this->isPreprint($link)) {
24
                $this->list[] = $link;
25
            }
26
        }
27
28
        return $this->list;
29
    }
30
31
    private function hasPreprint(array $link): bool
32
    {
33
        if (! array_key_exists('has_preprint', $link)) {
34
            return false;
35
        }
36
37
        return ! in_array(strtolower($link['has_preprint']), $this->knownIdentifierValues('has_preprint'));
38
    }
39
40
    private function isPreprint(array $link): bool
41
    {
42
        if (! array_key_exists('is_preprint_of', $link)) {
43
            return false;
44
        }
45
46
        return ! in_array(strtolower($link['is_preprint_of']), $this->knownIdentifierValues('is_preprint_of'));
47
    }
48
}
49