Conditions | 12 |
Paths | 58 |
Total Lines | 66 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
68 | public function processRefContent(string $refContent): string |
||
69 | { |
||
70 | // todo // hack Temporary Skip URL |
||
71 | if (preg_match('#books\.google#', $refContent)) { |
||
72 | $this->log->stats->increment('externref.skip.booksgoogle'); |
||
|
|||
73 | return $refContent; |
||
74 | } |
||
75 | |||
76 | try { |
||
77 | $result = $this->transformer->process($refContent, $this->summary); |
||
78 | } catch (Throwable $e) { |
||
79 | $this->log->critical( |
||
80 | 'Error patate34 ' . $e->getMessage() . " " . $e->getFile() . ":" . $e->getLine(), |
||
81 | ['stats' => 'externref.exception.patate34'] |
||
82 | ); |
||
83 | // TODO : parse $e->message -> variable process, taskName, botflag... |
||
84 | |||
85 | return $refContent; |
||
86 | } |
||
87 | |||
88 | if (trim($result) === trim($refContent)) { |
||
89 | $this->log->stats->increment('externref.transform.same'); |
||
90 | |||
91 | return $refContent; |
||
92 | } |
||
93 | |||
94 | // Gestion semi-auto : todo CONDITION POURRI FAUSSE $this->transformer->skipUnauthorised |
||
95 | |||
96 | $this->printDiff($refContent, $result, 'echo'); |
||
97 | if (!$this->autoOrYesConfirmation('Conserver cette modif ?')) { |
||
98 | return $refContent; |
||
99 | } |
||
100 | |||
101 | |||
102 | if (preg_match('#{{lien brisé#i', $result)) { |
||
103 | $this->log->stats->increment('externref.transform.lienbrisé'); |
||
104 | $this->summary->memo['count lien brisé'] = 1 + ($this->summary->memo['count lien brisé'] ?? 0); |
||
105 | if ($this->summary->memo['count lien brisé'] >= self::DEAD_LINK_NO_BOTFLAG) { |
||
106 | $this->summary->setBotFlag(false); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | if (str_contains($result, self::STRING_WIKIWIX_URL)) { |
||
111 | $this->log->stats->increment('externref.transform.wikiwix'); |
||
112 | $this->summary->memo['wikiwix'] = 1 + ($this->summary->memo['wikiwix'] ?? 0); |
||
113 | if ($this->summary->memo['wikiwix'] >= self::DEAD_LINK_NO_BOTFLAG) { |
||
114 | $this->summary->setBotFlag(false); |
||
115 | } |
||
116 | } |
||
117 | // not httpS in 2023 |
||
118 | if (str_contains($result, self::STRING_WAYBACK_URL)) { |
||
119 | $this->log->stats->increment('externref.transform.wayback'); |
||
120 | $this->summary->memo['wayback'] = 1 + ($this->summary->memo['wayback'] ?? 0); |
||
121 | if ($this->summary->memo['wayback'] >= self::DEAD_LINK_NO_BOTFLAG) { |
||
122 | $this->summary->setBotFlag(false); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | if ($this->summary->citationNumber >= self::CITATION_NUMBER_NO_BOTFLAG) { |
||
127 | $this->summary->setBotFlag(false); |
||
128 | } |
||
129 | |||
130 | $this->log->stats->increment('externref.transform.total'); |
||
131 | $this->summary->memo['count URL'] = 1 + ($this->summary->memo['count URL'] ?? 0); |
||
132 | |||
133 | return $result; |
||
134 | } |
||
194 |