Passed
Branch dev3 (024e59)
by Dispositif
12:55
created
src/Application/Traits/BotWorkerTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
     protected function printTitle(string $title): void
53 53
     {
54 54
         echo "---------------------\n";
55
-        echo date('d-m-Y H:i:s') . ' ' . Color::BG_CYAN . "  $title " . Color::NORMAL . "\n";
55
+        echo date('d-m-Y H:i:s').' '.Color::BG_CYAN."  $title ".Color::NORMAL."\n";
56 56
     }
57 57
 
58 58
     protected function canProcessTitleArticle(string $title, ?string $text): bool
Please login to merge, or discard this patch.
src/Application/AbstractBotTaskWorker.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     public const SLEEP_AFTER_EDITION = 60;
33 33
     public const MINUTES_DELAY_AFTER_LAST_HUMAN_EDIT = 15;
34 34
     public const CHECK_EDIT_CONFLICT = true;
35
-    public const ARTICLE_ANALYZED_FILENAME = __DIR__ . '/resources/article_edited.txt';
35
+    public const ARTICLE_ANALYZED_FILENAME = __DIR__.'/resources/article_edited.txt';
36 36
     public const SKIP_LASTEDIT_BY_BOT = true;
37 37
     public const SKIP_NOT_IN_MAIN_WIKISPACE = true;
38 38
     public const SKIP_ADQ = true;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         $this->initializePastAnalyzedTitles();
87 87
 
88 88
         // @throw exception on "Invalid CSRF token"
89
-        $this->run();//todo delete that and use (Worker)->run($duration) or process management
89
+        $this->run(); //todo delete that and use (Worker)->run($duration) or process management
90 90
     }
91 91
 
92 92
     protected function setUpInConstructor(): void
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     final public function run(): void
103 103
     {
104
-        echo date('d-m-Y H:i:s') . " *** NEW WORKER ***\n";
104
+        echo date('d-m-Y H:i:s')." *** NEW WORKER ***\n";
105 105
         foreach ($this->getTitles() as $title) {
106 106
             try {
107 107
                 $this->titleProcess($title);
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 
203 203
             // If not a critical edition error
204 204
             // example : Wiki Conflict : Page has been edited after getText()
205
-            echo "Error : " . $e->getMessage() . "\n";
205
+            echo "Error : ".$e->getMessage()."\n";
206 206
             $this->log->warning($e->getMessage());
207 207
 
208 208
             return;
209 209
         }
210 210
 
211 211
         dump($result);
212
-        echo "Sleep " . static::SLEEP_AFTER_EDITION . "\n";
212
+        echo "Sleep ".static::SLEEP_AFTER_EDITION."\n";
213 213
         sleep(static::SLEEP_AFTER_EDITION);
214 214
     }
215 215
 
Please login to merge, or discard this patch.
src/Application/TalkBotConfig.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 class TalkBotConfig extends WikiBotConfig
24 24
 {
25 25
     public const BOT_TALK_SUMMARY = 'Réponse artificielle';
26
-    public const BOT_TALK_FILE = __DIR__ . '/resources/phrases_zizibot.txt';
27
-    public const TALKCONFIG_FILENAME = __DIR__ . '/resources/botTalk_config.json';
26
+    public const BOT_TALK_FILE = __DIR__.'/resources/phrases_zizibot.txt';
27
+    public const TALKCONFIG_FILENAME = __DIR__.'/resources/botTalk_config.json';
28 28
 
29 29
     /**
30 30
      * Add a freaky response in the bottom of the talk page.
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         // ugly dependency
38 38
         $wiki = ServiceFactory::getMediawikiFactory();
39 39
         if (!$pageTitle) {
40
-            $pageTitle = 'Discussion utilisateur:' . $this::getBotName();
40
+            $pageTitle = 'Discussion utilisateur:'.$this::getBotName();
41 41
         }
42 42
         $page = new WikiPageAction($wiki, $pageTitle);
43 43
         $last = $page->page->getRevisions()->getLatest();
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
 
58 58
         // No response if time < 24h since last bot owner response
59 59
         if ($last->getUser() == self::getBotOwner()) {
60
-            $talkConfig['owner_last_time'] = (int)strtotime($last->getTimestamp());
60
+            $talkConfig['owner_last_time'] = (int) strtotime($last->getTimestamp());
61 61
             file_put_contents(self::TALKCONFIG_FILENAME, json_encode($talkConfig, JSON_THROW_ON_ERROR));
62 62
 
63 63
             return false;
64 64
         }
65 65
         // No response if time < 24h since last owner response
66
-        if (isset($talkConfig['owner_last_time']) && (int)$talkConfig['owner_last_time'] > (time() - 60 * 60 * 48)) {
66
+        if (isset($talkConfig['owner_last_time']) && (int) $talkConfig['owner_last_time'] > (time() - 60 * 60 * 48)) {
67 67
             echo "No response if time < 24h after last owner response\n";
68 68
 
69 69
             return false;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         $editInfo = new EditInfo(static::BOT_TALK_SUMMARY);
80 80
         $success = $page->addToBottomOfThePage($addText, $editInfo);
81 81
 
82
-        return (bool)$success;
82
+        return (bool) $success;
83 83
     }
84 84
 
85 85
     /**
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
         $lines = explode("\n", trim($text));
111 111
         $lastLine = $lines[count($lines) - 1];
112 112
         if (preg_match('#^(:*).+#', $lastLine, $matches) && !empty($matches[1])) {
113
-            $nextIdent = $matches[1] . ':';
113
+            $nextIdent = $matches[1].':';
114 114
             if (empty($author)) {
115 115
                 return $nextIdent;
116 116
             }
117 117
             // search author signature link to check that he wrote on the page bottom
118 118
             if (preg_match(
119
-                '#\[\[(?:User|Utilisateur|Utilisatrice):' . preg_quote($author, '#') . '[|\]]#i',
119
+                '#\[\[(?:User|Utilisateur|Utilisatrice):'.preg_quote($author, '#').'[|\]]#i',
120 120
                 $matches[0]
121 121
             )
122 122
             ) {
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
             throw new ConfigException('Pas de phrases disponibles pour TalkBot');
138 138
         }
139 139
 
140
-        return (string)trim($sentences[array_rand($sentences)]);
140
+        return (string) trim($sentences[array_rand($sentences)]);
141 141
     }
142 142
 
143 143
     /**
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     public function botContribs(): string
148 148
     {
149 149
         $url
150
-            = 'https://fr.wikipedia.org/w/api.php?action=query&list=usercontribs&ucuser=' . $this::getBotName()
150
+            = 'https://fr.wikipedia.org/w/api.php?action=query&list=usercontribs&ucuser='.$this::getBotName()
151 151
             . '&ucnamespace=0&uclimit=40&ucprop=title|timestamp|comment&format=json';
152 152
 
153 153
         return file_get_contents($url);
Please login to merge, or discard this patch.
src/Application/WikiPageAction.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
             $this->page = $wiki->newPageGetter()->getFromTitle($title);
64 64
             $this->ns = $this->page->getPageIdentifier()->getTitle()->getNs();
65 65
         } catch (Throwable $e) {
66
-            throw new Exception('Erreur construct WikiPageAction ' . $e->getMessage() . $e->getFile() . $e->getLine(), $e->getCode(), $e);
66
+            throw new Exception('Erreur construct WikiPageAction '.$e->getMessage().$e->getFile().$e->getLine(), $e->getCode(), $e);
67 67
         }
68 68
     }
69 69
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     public function getRedirect(): ?string
132 132
     {
133 133
         if ($this->getText() && preg_match('/^#REDIRECT(?:ION)? ?\[\[([^]]+)]]/i', $this->getText(), $matches)) {
134
-            return (string)trim($matches[1]);
134
+            return (string) trim($matches[1]);
135 135
         }
136 136
 
137 137
         return null;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             throw new Exception('That page does not exist');
223 223
         }
224 224
         $oldText = $this->getText();
225
-        $newText = $oldText . "\n" . $addText;
225
+        $newText = $oldText."\n".$addText;
226 226
 
227 227
         return $this->editPage($newText, $editInfo);
228 228
     }
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
             throw new Exception('That page does not exist');
240 240
         }
241 241
         $oldText = $this->getText();
242
-        $newText = $addText . $oldText;
242
+        $newText = $addText.$oldText;
243 243
 
244 244
         return $this->editPage($newText, $editInfo);
245 245
     }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         // "{{en}} {{zh}} {{ouvrage...}}"
255 255
         // todo test U
256 256
         if (preg_match_all(
257
-            '#(?<langTemp>{{[a-z][a-z]}} ?{{[a-z][a-z]}}) ?' . preg_quote($tplOrigin, '#') . '#i',
257
+            '#(?<langTemp>{{[a-z][a-z]}} ?{{[a-z][a-z]}}) ?'.preg_quote($tplOrigin, '#').'#i',
258 258
             $text,
259 259
             $matches
260 260
         )
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
         // hack // todo: autres patterns {{en}} ?
269 269
         // OK : {{en}} \n {{ouvrage}}
270 270
         if (preg_match_all(
271
-                "#(?<langTemp>{{(?<lang>[a-z][a-z])}} *\n?)?" . preg_quote($tplOrigin, '#') . '#i',
271
+                "#(?<langTemp>{{(?<lang>[a-z][a-z])}} *\n?)?".preg_quote($tplOrigin, '#').'#i',
272 272
                 $text,
273 273
                 $matches
274 274
             ) > 0
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 // example : {{en}} {{template|lang=ru}}
284 284
                 if (!empty($lang) && self::SKIP_LANG_INDICATOR !== $lang
285 285
                     && preg_match('#langue *=#', $tplReplace)
286
-                    && !preg_match('#langue *= ?' . $lang . '#i', $tplReplace)
286
+                    && !preg_match('#langue *= ?'.$lang.'#i', $tplReplace)
287 287
                     && !preg_match('#\| ?langue *= ?\n?\|#', $tplReplace)
288 288
                 ) {
289 289
                     echo sprintf(
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
                 // FIX dirty : {{en}} mais langue= avec value non définie sur new template...
307 307
                 if (!empty($lang) && preg_match('#\| ?(langue *=) ?\n? ?\|#', $tplReplace, $matchLangue) > 0) {
308 308
                     $previousTpl = $tplReplace;
309
-                    $tplReplace = str_replace($matchLangue[1], 'langue=' . $lang, $tplReplace);
309
+                    $tplReplace = str_replace($matchLangue[1], 'langue='.$lang, $tplReplace);
310 310
                     //dump('origin', $tplOrigin);
311 311
                     $text = str_replace($previousTpl, $tplReplace, $text);
312 312
                 }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
                 // replace {template} and {{lang}} {template}
322 322
                 $text = str_replace($mention, $tplReplace, $text);
323 323
                 $text = str_replace(
324
-                    $matches['langTemp'][$num] . $tplReplace,
324
+                    $matches['langTemp'][$num].$tplReplace,
325 325
                     $tplReplace,
326 326
                     $text
327 327
                 ); // si 1er replace global sans
Please login to merge, or discard this patch.
src/Infrastructure/InternetDomainParser.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class InternetDomainParser implements InternetDomainParserInterface
23 23
 {
24
-    private const PATH_CACHE_PUBLIC_SUFFIX_LIST = __DIR__ . '/resources/public_suffix_list.dat';
24
+    private const PATH_CACHE_PUBLIC_SUFFIX_LIST = __DIR__.'/resources/public_suffix_list.dat';
25 25
 
26 26
     /** @var Rules */
27 27
     private $rules;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public static function extractSubdomainString(string $httpURL): string
56 56
     {
57 57
         if (!ExternHttpClient::isHttpURL($httpURL)) {
58
-            throw new Exception('string is not an URL ' . $httpURL);
58
+            throw new Exception('string is not an URL '.$httpURL);
59 59
         }
60 60
 
61 61
         return parse_url($httpURL, PHP_URL_HOST);
Please login to merge, or discard this patch.
src/Domain/ExternLink/ExternPage.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     )
70 70
     {
71 71
         if (!ExternHttpClient::isHttpURL($url)) {
72
-            throw new Exception('string is not an URL ' . $url);
72
+            throw new Exception('string is not an URL '.$url);
73 73
         }
74 74
         $this->url = $url;
75 75
         $this->html = $html;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     {
190 190
         try {
191 191
             if (!ExternHttpClient::isHttpURL($this->url)) {
192
-                throw new Exception('string is not an URL ' . $this->url);
192
+                throw new Exception('string is not an URL '.$this->url);
193 193
             }
194 194
             if (!$this->domainParser instanceof InternetDomainParserInterface) {
195 195
                 $this->log->notice('InternetDomainParser is not set');
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             return $this->domainParser->getRegistrableDomainFromURL($this->url);
201 201
         } catch (Exception $e) {
202 202
             if ($this->log !== null) {
203
-                $this->log->warning('InternetDomainParser->getRegistrableDomainFromURL NULL ' . $this->url);
203
+                $this->log->warning('InternetDomainParser->getRegistrableDomainFromURL NULL '.$this->url);
204 204
             }
205 205
             throw new Exception('InternetDomainParser->getRegistrableDomainFromURL NULL', $e->getCode(), $e);
206 206
         }
Please login to merge, or discard this patch.
src/Domain/ExternLink/ExternHttpErrorLogic.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 class ExternHttpErrorLogic
16 16
 {
17
-    public const LOG_REQUEST_ERROR = __DIR__ . '/../../Application/resources/external_request_error.log';
17
+    public const LOG_REQUEST_ERROR = __DIR__.'/../../Application/resources/external_request_error.log';
18 18
 
19 19
     /**
20 20
      * @var LoggerInterface
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
             }
47 47
             return $url;
48 48
         } elseif (preg_match('#401 Unauthorized#i', $errorMessage)) {
49
-            $this->log->notice('401 Unauthorized : skip ' . $url);
49
+            $this->log->notice('401 Unauthorized : skip '.$url);
50 50
 
51 51
             return $url;
52 52
         } else {
53 53
             //  autre : ne pas générer de {lien brisé}, car peut-être 404 temporaire
54
-            $this->log->warning('erreur sur extractWebData ' . $errorMessage);
54
+            $this->log->warning('erreur sur extractWebData '.$errorMessage);
55 55
 
56 56
             //file_put_contents(self::LOG_REQUEST_ERROR, $this->domain."\n", FILE_APPEND);
57 57
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     {
79 79
         $text = str_replace(['https://', 'http://', 'www.'], '', $url);
80 80
         if (strlen($text) > 30) {
81
-            $text = substr($text, 0, 30) . '…';
81
+            $text = substr($text, 0, 30).'…';
82 82
         }
83 83
 
84 84
         return $text;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 
87 87
     protected function log403(string $url): void
88 88
     {
89
-        $this->log->warning('403 Forbidden : ' . $url);
90
-        file_put_contents(self::LOG_REQUEST_ERROR, '403 Forbidden : ' . $url . "\n", FILE_APPEND);
89
+        $this->log->warning('403 Forbidden : '.$url);
90
+        file_put_contents(self::LOG_REQUEST_ERROR, '403 Forbidden : '.$url."\n", FILE_APPEND);
91 91
     }
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
src/Domain/ExternLink/ExternRefTransformer.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
     use SummaryExternTrait, RobotsRulesTrait, PublisherLogicTrait;
32 32
 
33 33
     public const HTTP_REQUEST_LOOP_DELAY = 10;
34
-    public const SKIP_DOMAIN_FILENAME = __DIR__ . '/../resources/config_skip_domain.txt';
34
+    public const SKIP_DOMAIN_FILENAME = __DIR__.'/../resources/config_skip_domain.txt';
35 35
     public const REPLACE_404 = true;
36
-    public const CONFIG_PRESSE = __DIR__ . '/../resources/config_presse.yaml';
37
-    public const CONFIG_NEWSPAPER_JSON = __DIR__ . '/../resources/data_newspapers.json';
38
-    public const CONFIG_SCIENTIFIC_JSON = __DIR__ . '/../resources/data_scientific_domain.json';
39
-    public const CONFIG_SCIENTIFIC_WIKI_JSON = __DIR__ . '/../resources/data_scientific_wiki.json';
36
+    public const CONFIG_PRESSE = __DIR__.'/../resources/config_presse.yaml';
37
+    public const CONFIG_NEWSPAPER_JSON = __DIR__.'/../resources/data_newspapers.json';
38
+    public const CONFIG_SCIENTIFIC_JSON = __DIR__.'/../resources/data_scientific_domain.json';
39
+    public const CONFIG_SCIENTIFIC_WIKI_JSON = __DIR__.'/../resources/data_scientific_wiki.json';
40 40
 
41 41
     public $skipSiteBlacklisted = true;
42 42
     public $skipRobotNoIndex = true;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     protected function isSiteBlackListed(): bool
161 161
     {
162 162
         if ($this->skipSiteBlacklisted && in_array($this->registrableDomain, $this->skip_domain)) {
163
-            $this->log->notice("Skip web site " . $this->registrableDomain);
163
+            $this->log->notice("Skip web site ".$this->registrableDomain);
164 164
             return true;
165 165
         }
166 166
         return false;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $this->config[$domain] = is_array($this->config[$domain]) ? $this->config[$domain] : [];
179 179
 
180 180
         if ($this->config[$domain] === 'deactivated' || isset($this->config[$domain]['deactivated'])) {
181
-            $this->log->info("Domain " . $domain . " disabled\n");
181
+            $this->log->info("Domain ".$domain." disabled\n");
182 182
 
183 183
             return false;
184 184
         }
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
     protected function logDebugConfigWebDomain(string $domain): void
193 193
     {
194 194
         if (!isset($this->config[$domain])) {
195
-            $this->log->debug("Domain " . $domain . " non configuré");
195
+            $this->log->debug("Domain ".$domain." non configuré");
196 196
         } else {
197
-            $this->log->debug("Domain " . $domain . " configuré");
197
+            $this->log->debug("Domain ".$domain." configuré");
198 198
         }
199 199
     }
200 200
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         if ($pageData === []
220 220
             || (empty($pageData['JSON-LD']) && empty($pageData['meta']))
221 221
         ) {
222
-            $this->log->notice('No metadata : ' . $url);
222
+            $this->log->notice('No metadata : '.$url);
223 223
 
224 224
             return true;
225 225
         }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
     protected function emptyMapData(array $mapData, string $url): bool
235 235
     {
236 236
         if ($mapData === [] || empty($mapData['url']) || empty($mapData['titre'])) {
237
-            $this->log->info('Mapping incomplet : ' . $url);
237
+            $this->log->info('Mapping incomplet : '.$url);
238 238
 
239 239
             return true;
240 240
         }
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 
292 292
         $template = WikiTemplateFactory::create($templateName);
293 293
         $template->userSeparator = " |";
294
-        $this->summary->memo['count ' . $templateName] = 1 + ($this->summary->memo['count ' . $templateName] ?? 0);
294
+        $this->summary->memo['count '.$templateName] = 1 + ($this->summary->memo['count '.$templateName] ?? 0);
295 295
 
296 296
         return $template;
297 297
     }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         $templateOptimized = $optimizer->getOptiTemplate();
350 350
 
351 351
         $serialized = $templateOptimized->serialize(true);
352
-        $this->log->info('Serialized 444: ' . $serialized . "\n");
352
+        $this->log->info('Serialized 444: '.$serialized."\n");
353 353
         return $serialized;
354 354
     }
355 355
 }
Please login to merge, or discard this patch.
src/Domain/ExternLink/RobotsRulesTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
                 || stripos($robots, 'none') !== false
28 28
             )
29 29
         ) {
30
-            $this->log->notice('robots NOINDEX : ' . $url);
30
+            $this->log->notice('robots NOINDEX : '.$url);
31 31
 
32 32
             return !$this->isNoIndexDomainWhitelisted($pageData['meta']['prettyDomainName']);
33 33
         }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     protected function isNoIndexDomainWhitelisted(?string $prettyDomain): bool
39 39
     {
40 40
         if (in_array($prettyDomain ?? '', $this->noindexWhitelist)) {
41
-            $this->log->notice('ROBOT_NOINDEX_WHITELIST ' . $prettyDomain);
41
+            $this->log->notice('ROBOT_NOINDEX_WHITELIST '.$prettyDomain);
42 42
 
43 43
             return true;
44 44
         }
Please login to merge, or discard this patch.