Passed
Branch dev3 (d976d5)
by Dispositif
02:50
created

GoogleBooksHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 14 3
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 GoogleBooksHandler 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('GOOGLE...');
38
39
            return OuvrageFactory::GoogleFromIsbn($this->isbn);
40
        } catch (Throwable $e) {
41
            $this->logger->warning("*** ERREUR GOOGLE Isbn Search ***" . $e->getMessage());
42
            if (strpos($e->getMessage(), 'Could not resolve host: www.googleapis.com') === false) {
43
                throw $e;
44
            }
45
        }
46
47
        return null;
48
    }
49
}