IdentifierResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
dl 0
loc 50
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 11 3
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor;
4
5
use PubPeerFoundation\PublicationDataExtractor\Exceptions\UnknownIdentifierException;
6
use PubPeerFoundation\PublicationDataExtractor\Identifiers\Identifier;
7
8
class IdentifierResolver
9
{
10
    /**
11
     * List of available Identifiers.
12
     *
13
     * @var array
14
     */
15
    protected $identifiers = [
16
        Identifiers\BioRxiv::class,
17
        Identifiers\Figshare::class,
18
        Identifiers\Doi::class,
19
        Identifiers\Arxiv::class,
20
        Identifiers\Pubmed::class,
21
    ];
22
23
    /**
24
     * The query string.
25
     *
26
     * @var string
27
     */
28
    private $queryString;
29
30
    /**
31
     * Identifier constructor.
32
     *
33
     * @param  string  $queryString
34
     */
35
    public function __construct(string $queryString)
36
    {
37
        $this->queryString = $queryString;
38
    }
39
40
    /**
41
     * Resolves the Identifier;.
42
     *
43
     * @return Identifiers\Identifier
44
     *
45
     * @throws UnknownIdentifierException
46
     */
47
    public function handle(): Identifier
48
    {
49
        foreach ($this->identifiers as $identifierClass) {
50
            $identifier = new $identifierClass($this->queryString);
51
52
            if ($identifier->isValid()) {
53
                return $identifier;
54
            }
55
        }
56
57
        throw new UnknownIdentifierException();
58
    }
59
}
60