Completed
Push — master ( 84b0dd...9db430 )
by Xavier
04:12
created

IdentifierResolver::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Identifiers;
4
5
use PubPeerFoundation\PublicationDataExtractor\Exceptions\UnknownIdentifierException;
6
7
class IdentifierResolver
8
{
9
    /**
10
     * List of available Identifiers.
11
     *
12
     * @var array
13
     */
14
    protected $identifiers = [
15
        BioArxiv::class,
16
        Figshare::class,
17
        Doi::class,
18
        Arxiv::class,
19
        Pubmed::class,
20
    ];
21
22
    /**
23
     * The query string.
24
     *
25
     * @var string
26
     */
27
    private $queryString;
28
29
    /**
30
     * Identifier constructor.
31
     *
32
     * @param string $queryString
33
     */
34
    public function __construct(string $queryString)
35
    {
36
        $this->queryString = $queryString;
37
    }
38
39
    /**
40
     * Resolves the Identifier;.
41
     *
42
     * @return Identifier
43
     *
44
     * @throws UnknownIdentifierException
45
     */
46
    public function handle()
47
    {
48
        foreach ($this->identifiers as $identifierClass) {
49
            $identifier = new $identifierClass($this->queryString);
50
51
            if ($identifier->isValid()) {
52
                return $this->validIdentifier = $identifier;
0 ignored issues
show
Bug introduced by
The property validIdentifier does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
            }
54
        }
55
56
        throw new UnknownIdentifierException();
57
    }
58
59
}
60