| Conditions | 2 |
| Paths | 2 |
| Total Lines | 101 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 73 | private function rewriteLegacyPathsToPublic(string $html, string $title, int $id): string |
||
| 74 | { |
||
| 75 | $countAll = 0; |
||
| 76 | |||
| 77 | // {IMG_DIR}filename.ext -> /img/filename.ext |
||
| 78 | $html = preg_replace( |
||
| 79 | '#(\burl\(\s*[\'"]?)\{IMG_DIR\}#i', |
||
| 80 | '$1/img/', |
||
| 81 | $html, |
||
| 82 | -1, |
||
| 83 | $c1 |
||
| 84 | ); $countAll += (int)$c1; |
||
| 85 | |||
| 86 | $html = preg_replace( |
||
| 87 | '#(\bsrc=\s*[\'"])\{IMG_DIR\}#i', |
||
| 88 | '$1/img/', |
||
| 89 | $html, |
||
| 90 | -1, |
||
| 91 | $c1b |
||
| 92 | ); $countAll += (int)$c1b; |
||
| 93 | |||
| 94 | // {REL_PATH}main/img/... -> /img/... |
||
| 95 | $html = preg_replace( |
||
| 96 | '#(\burl\(\s*[\'"]?)\{REL_PATH\}main/img/#i', |
||
| 97 | '$1/img/', |
||
| 98 | $html, |
||
| 99 | -1, |
||
| 100 | $c2 |
||
| 101 | ); $countAll += (int)$c2; |
||
| 102 | |||
| 103 | $html = preg_replace( |
||
| 104 | '#(\bsrc=\s*[\'"])\{REL_PATH\}main/img/#i', |
||
| 105 | '$1/img/', |
||
| 106 | $html, |
||
| 107 | -1, |
||
| 108 | $c2b |
||
| 109 | ); $countAll += (int)$c2b; |
||
| 110 | |||
| 111 | // Raw /main/img/... -> /img/... |
||
| 112 | $html = preg_replace( |
||
| 113 | '#(\burl\(\s*[\'"]?)/main/img/#i', |
||
| 114 | '$1/img/', |
||
| 115 | $html, |
||
| 116 | -1, |
||
| 117 | $c3 |
||
| 118 | ); $countAll += (int)$c3; |
||
| 119 | |||
| 120 | $html = preg_replace( |
||
| 121 | '#(\bsrc=\s*[\'"])/main/img/#i', |
||
| 122 | '$1/img/', |
||
| 123 | $html, |
||
| 124 | -1, |
||
| 125 | $c3b |
||
| 126 | ); $countAll += (int)$c3b; |
||
| 127 | |||
| 128 | // {COURSE_DIR}images/... -> /img/... |
||
| 129 | $html = preg_replace( |
||
| 130 | '#(\burl\(\s*[\'"]?)\{COURSE_DIR\}images/#i', |
||
| 131 | '$1/img/', |
||
| 132 | $html, |
||
| 133 | -1, |
||
| 134 | $c4 |
||
| 135 | ); $countAll += (int)$c4; |
||
| 136 | |||
| 137 | $html = preg_replace( |
||
| 138 | '#(\bsrc=\s*[\'"])\{COURSE_DIR\}images/#i', |
||
| 139 | '$1/img/', |
||
| 140 | $html, |
||
| 141 | -1, |
||
| 142 | $c4b |
||
| 143 | ); $countAll += (int)$c4b; |
||
| 144 | |||
| 145 | // /img/certificates/... -> /img/... |
||
| 146 | $html = preg_replace( |
||
| 147 | '#(\burl\(\s*[\'"]?)/img/certificates/#i', |
||
| 148 | '$1/img/', |
||
| 149 | $html, |
||
| 150 | -1, |
||
| 151 | $c5 |
||
| 152 | ); $countAll += (int)$c5; |
||
| 153 | |||
| 154 | $html = preg_replace( |
||
| 155 | '#(\bsrc=\s*[\'"])/img/certificates/#i', |
||
| 156 | '$1/img/', |
||
| 157 | $html, |
||
| 158 | -1, |
||
| 159 | $c5b |
||
| 160 | ); $countAll += (int)$c5b; |
||
| 161 | |||
| 162 | $html = preg_replace('#/img//+#', '/img/', $html, -1, $c6); $countAll += (int)$c6; |
||
| 163 | |||
| 164 | if ($countAll > 0) { |
||
| 165 | $this->dbg(sprintf( |
||
| 166 | '[MIG][templates] id=%d title="%s" rewrites=%d', |
||
| 167 | $id, |
||
| 168 | $title, |
||
| 169 | $countAll |
||
| 170 | )); |
||
| 171 | } |
||
| 172 | |||
| 173 | return $html; |
||
| 174 | } |
||
| 274 |