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

IsbnBanValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 6 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
11
namespace App\Application\OuvrageComplete\Validators;
12
13
class IsbnBanValidator implements CompleteValidatorInterface
14
{
15
    /**
16
     * Exclusion requête BnF/Google/etc
17
     * Format EAN ou ISBN10 sans tiret.
18
     */
19
    public const ISBN_EAN_SKIP
20
        = [
21
            '9782918758440', // Profils de lignes du réseau ferré français vol.2
22
            '9782918758341', // Profils de lignes du réseau ferré français vol.1
23
            '285608043X', // Dictionnaire encyclopédique d'électronique (langue erronée)
24
            '9782021401196', // sous-titre erroné
25
        ];
26
27
    /**
28
     * @var string
29
     */
30
    protected $isbn;
31
    /**
32
     * @var string|null
33
     */
34
    protected $isbn10;
35
36
    public function __construct(string $isbn, ?string $isbn10 = null)
37
    {
38
        $this->isbn = $isbn;
39
        $this->isbn10 = $isbn10;
40
    }
41
42
    public function validate(): bool
43
    {
44
        return !in_array(str_replace('-', '', $this->isbn), self::ISBN_EAN_SKIP)
45
            && (
46
                $this->isbn10 === null
47
                || !in_array(str_replace('-', '', $this->isbn10), self::ISBN_EAN_SKIP)
48
            );
49
    }
50
}