Passed
Push — master ( fd6b1a...a766ea )
by Dispositif
02:28
created

ImportantSummaryCreator::parseBNFdata()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 3
nc 2
nop 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
namespace App\Application\OuvrageEdit;
11
12
use LogicException;
13
14
/**
15
 * For substantive or ambiguous modifications done.
16
 * Move to /Domain ?
17
 */
18
class ImportantSummaryCreator
19
{
20
    /**
21
     * @var PageWorkStatus
22
     */
23
    protected $pageWorkStatus;
24
25
    public function __construct(PageWorkStatus $pageWorkStatus)
26
    {
27
        $this->pageWorkStatus = $pageWorkStatus;
28
    }
29
30
    public function processPageOuvrage(array $ouvrageData): void
31
    {
32
        if ($this->pageWorkStatus->getTitle() !== $ouvrageData['page']) {
33
            throw new LogicException('Title mismatch between PageWorkStatus and ouvrageData');
34
        }
35
36
        $this->parseParamNotCorrected($ouvrageData['opti']);
37
38
        $this->parseOpti($ouvrageData['opti']);
39
40
        $this->parseModifs($ouvrageData['modifs']);
41
    }
42
43
    protected function parseParamNotCorrected(string $opti)
44
    {
45
        // paramètre inconnu
46
        if (preg_match_all(
47
                "#\|[^|]+<!-- ?(PARAMETRE [^>]+ N'EXISTE PAS|VALEUR SANS NOM DE PARAMETRE|ERREUR [^>]+) ?-->#",
48
                $opti,
49
                $matches
50
            ) > 0
51
        ) {
52
            foreach ($matches[0] as $line) {
53
                $this->addErrorWarning($line);
54
            }
55
            //  $this->pageWorkStatus->botFlag = false;
56
            $this->addSummaryTag('paramètre non corrigé');
57
        }
58
    }
59
60
    protected function addErrorWarning(string $string)
61
    {
62
        $this->pageWorkStatus->addErrorWarning($string);
63
    }
64
65
    protected function addSummaryTag(string $string)
66
    {
67
        $this->pageWorkStatus->addSummaryTag($string);
68
    }
69
70
    protected function parseOpti(string $opti): void
71
    {
72
        // ISBN invalide
73
        if (preg_match("#isbn invalide ?=[^|}]+#i", $opti, $matches) > 0) {
74
            $this->addErrorWarning($matches[0]);
75
            $this->pageWorkStatus->botFlag = false;
76
            $this->addSummaryTag('ISBN invalide 💩');
77
        }
78
    }
79
80
    protected function parseModifs(string $modifs): void
81
    {
82
        // Edits avec ajout conséquent de donnée
83
        if (preg_match('#distinction des auteurs#', $modifs) > 0) {
84
            $this->pageWorkStatus->botFlag = false;
85
            $this->addSummaryTag('distinction auteurs 🧠');
86
        }
87
        // prédiction paramètre correct
88
        if (preg_match('#[^,]+(=>|⇒)[^,]+#', $modifs, $matches) > 0) {
89
            $this->pageWorkStatus->botFlag = false;
90
            $this->addSummaryTag($matches[0]);
91
        }
92
        if (preg_match('#\+\+sous-titre#', $modifs) > 0) {
93
            $this->pageWorkStatus->botFlag = false;
94
            $this->addSummaryTag('+sous-titre');
95
        }
96
        if (preg_match('#\+lieu#', $modifs) > 0) {
97
            $this->addSummaryTag('+lieu');
98
        }
99
        if (preg_match('#tracking#', $modifs) > 0) {
100
            $this->addSummaryTag('tracking');
101
        }
102
        if (preg_match('#présentation en ligne#', $modifs) > 0) {
103
            $this->addSummaryTag('+présentation en ligne✨');
104
        }
105
        if (preg_match('#distinction auteurs#', $modifs) > 0) {
106
            $this->addSummaryTag('distinction auteurs 🧠');
107
        }
108
        if (preg_match('#\+lire en ligne#', $modifs) > 0) {
109
            $this->addSummaryTag('+lire en ligne✨');
110
        }
111
        if (preg_match('#\+lien #', $modifs) > 0) {
112
            $this->addSummaryTag('wikif');
113
        }
114
        if (preg_match('#\+éditeur#', $modifs) > 0) {
115
            $this->addSummaryTag('éditeur');
116
        }
117
        $this->parseBNFdata($modifs);
118
    }
119
120
    // mention BnF si ajout donnée + ajout identifiant bnf=
121
    protected function parseBNFdata(string $modifs): void
122
    {
123
        if (!empty($this->pageWorkStatus->importantSummary) && preg_match('#BnF#i', $modifs) > 0) {
124
            $this->addSummaryTag('©[[BnF]]');
125
        }
126
    }
127
}