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

OpenLibraryHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
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 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 2
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
namespace App\Application\OuvrageComplete\Handlers;
11
12
use App\Domain\Models\Wiki\OuvrageTemplate;
13
use App\Domain\OuvrageFactory;
14
use Psr\Log\LoggerInterface;
15
use Throwable;
16
17
class OpenLibraryHandler implements CompleteHandlerInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $isbn;
23
    /**
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
27
28
    public function __construct(string $isbn, LoggerInterface $logger)
29
    {
30
        $this->isbn = $isbn;
31
        $this->logger = $logger;
32
    }
33
34
    public function handle(): ?OuvrageTemplate
35
    {
36
        try {
37
            $this->logger->info('OpenLibrary...');
38
            return OuvrageFactory::OpenLibraryFromIsbn($this->isbn);
39
40
        } catch (Throwable $e) {
41
            $this->logger->warning('**** ERREUR OpenLibrary Isbn Search');
42
        }
43
44
        return null;
45
    }
46
}