Passed
Push — master ( 9e3ea7...ee24dc )
by Dispositif
02:33
created

WikidataSearchHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 2
A __construct() 0 5 1
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
11
namespace App\Application\OuvrageComplete\Handlers;
12
13
14
use App\Domain\InfrastructurePorts\WikidataAdapterInterface;
15
use App\Domain\Models\Wiki\OuvrageTemplate;
16
use App\Domain\Publisher\Wikidata2Ouvrage;
17
18
class WikidataSearchHandler implements CompleteHandlerInterface
19
{
20
21
    /**
22
     * @var OuvrageTemplate
23
     */
24
    protected $bnfOuvrage;
25
    /**
26
     * @var WikidataAdapterInterface
27
     */
28
    protected $wikidataAdapter;
29
    /**
30
     * @var string article title
31
     */
32
    protected $page;
33
34
    public function __construct(OuvrageTemplate $bnfOuvrage, WikidataAdapterInterface $wikidataAdapter, string $page)
35
    {
36
        $this->bnfOuvrage = $bnfOuvrage;
37
        $this->wikidataAdapter = $wikidataAdapter;
38
        $this->page = $page;
39
    }
40
41
    public function handle(): ?OuvrageTemplate
42
    {
43
        // Wikidata requests from $infos (ISBN/ISNI)
44
        if (!empty($this->bnfOuvrage->getInfos())) {
45
            // TODO try/catch
46
            $wdComplete = new Wikidata2Ouvrage($this->wikidataAdapter, clone $this->bnfOuvrage, $this->page);
47
            return $wdComplete->getOuvrage();
48
        }
49
50
        return null;
51
    }
52
}