| Conditions | 3 |
| Paths | 3 |
| Total Lines | 58 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 70 | private static function toHtml($title,array $links) |
||
| 71 | { |
||
| 72 | $html = '<!DOCTYPE HTML>'; |
||
| 73 | $html .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; |
||
| 74 | $html .= '<title>' . $title . '</title>'; |
||
| 75 | $html .= '<style>'; |
||
| 76 | $html .= '.error { color: red }'; |
||
| 77 | |||
| 78 | $html .= '.tooltip |
||
| 79 | { |
||
| 80 | display: inline; |
||
| 81 | position: relative; |
||
| 82 | text-decoration: none; |
||
| 83 | top: 0px; |
||
| 84 | left: 0px; |
||
| 85 | }'; |
||
| 86 | |||
| 87 | $html .= '.tooltip:hover:after |
||
| 88 | { |
||
| 89 | background: #333; |
||
| 90 | background: rgba(0,0,0,.8); |
||
| 91 | border-radius: 5px; |
||
| 92 | top: -5px; |
||
| 93 | color: #fff; |
||
| 94 | content: attr(data-tooltip); |
||
| 95 | left: 160px; |
||
| 96 | padding: 5px 15px; |
||
| 97 | position: absolute; |
||
| 98 | z-index: 98; |
||
| 99 | width: 150px; |
||
| 100 | }'; |
||
| 101 | $html .= '</style>'; |
||
| 102 | $html .= '</head><body>'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var GlLinkCheckerError $link |
||
| 106 | */ |
||
| 107 | foreach ($links as $link) { |
||
| 108 | $html .= '<div class="link">'; |
||
| 109 | $url = $link->getLink(); |
||
| 110 | $files = " -> " . implode(" ", $link->getFiles()); |
||
| 111 | $errors = $link->getErrorMessages(); |
||
| 112 | |||
| 113 | if (count($errors) <= 0) { |
||
| 114 | $html .= '<a href="' . $url . '">' . $url . '</a>' . $files; |
||
| 115 | $html .= '</div>'; |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | |||
| 119 | $tooltip = implode(' ', $errors); |
||
| 120 | $html .= '<a href="' . $url . '" class="error tooltip" data-tooltip="' . $tooltip . '">' . $url . '</a>' . $link->getStatusCode( |
||
| 121 | ) . $files; |
||
| 122 | $html .= '</div>'; |
||
| 123 | } |
||
| 124 | $html .= '<br><br><br></body></html>'; |
||
| 125 | |||
| 126 | return $html; |
||
| 127 | } |
||
| 128 | } |
||
| 129 |