Passed
Push — master ( fee625...9b7863 )
by Dispositif
05:51
created

EditSummaryTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B generateSummary() 0 36 7
A addSummaryTag() 0 4 2
1
<?php
2
/**
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019/2020 © Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
11
namespace App\Application;
12
13
14
trait EditSummaryTrait
15
{
16
    /**
17
     * For substantive or ambiguous modifications done.
18
     *
19
     * @param string $tag
20
     */
21
    private function addSummaryTag(string $tag)
22
    {
23
        if (!in_array($tag, $this->importantSummary)) {
24
            $this->importantSummary[] = $tag;
1 ignored issue
show
Bug Best Practice introduced by
The property importantSummary does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
        }
26
    }
27
28
    /**
29
     * todo extract
30
     * Generate wiki edition summary.
31
     *
32
     * @return string
33
     */
34
    public function generateSummary(): string
35
    {
36
        // Start summary with "WikiBotConfig" when using botFlag, else "*"
37
        $prefix = ($this->botFlag) ? 'bot' : '☆'; //🧐 🤖
38
        // add "/!\" when errorWarning
39
        $prefix .= (!empty($this->errorWarning)) ? ' ⚠️' : '';
40
41
        // basic modifs
42
        $citeSummary = implode(' ', $this->citationSummary);
43
        // replace by list of modifs to verify by humans
44
        if (!empty($this->importantSummary)) {
45
            $citeSummary = implode(', ', $this->importantSummary);
46
        }
47
48
        $summary = sprintf(
49
            '%s [%s/%s] %s %sx : %s',
50
            $prefix,
51
            str_replace('v', '', $this->bot::getGitVersion()),
52
            str_replace(['v0.', 'v1.'], '', $this->citationVersion),
53
            self::TASK_NAME,
1 ignored issue
show
Bug introduced by
The constant App\Application\EditSummaryTrait::TASK_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
54
            $this->nbRows,
55
            $citeSummary
56
        );
57
58
        if (!empty($this->importantSummary)) {
59
            $summary .= '...';
60
        }
61
62
        // shrink long summary if no important details to verify
63
        if (empty($this->importantSummary)) {
64
            $length = strlen($summary);
65
            $summary = mb_substr($summary, 0, 80);
66
            $summary .= ($length > strlen($summary)) ? '…' : '';
67
        }
68
69
        return $summary;
70
    }
71
72
}
73