| Conditions | 10 |
| Paths | 7 |
| Total Lines | 58 |
| Code Lines | 38 |
| 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 |
||
| 85 | private function scanContent($path) |
||
| 86 | { |
||
| 87 | // get file content plain |
||
| 88 | $content = File::read($path); |
||
| 89 | |||
| 90 | // nothing to check |
||
| 91 | if ($content === null || $content === false) { |
||
| 92 | return false; |
||
| 93 | } |
||
| 94 | |||
| 95 | $normalized = $this->normalizeContent($content); |
||
| 96 | |||
| 97 | // list malware signatures |
||
| 98 | $db = $this->signatures->getElementsByTagName('signature'); |
||
| 99 | $detected = false; |
||
| 100 | foreach ($db as $sig) { |
||
| 101 | $sigContent = $sig->nodeValue; |
||
| 102 | $attr = $sig->attributes; |
||
| 103 | $attrId = $attr->getNamedItem('id')->nodeValue; |
||
| 104 | $attrFormat = $attr->getNamedItem('format')->nodeValue; |
||
| 105 | $attrTitle = $attr->getNamedItem('title')->nodeValue; |
||
| 106 | $attrSever = $attr->getNamedItem('sever')->nodeValue; |
||
| 107 | |||
| 108 | switch ($attrFormat) { |
||
| 109 | case 're': |
||
| 110 | if ((preg_match('#(' . $sigContent . ')#smi', $content, $found, PREG_OFFSET_CAPTURE)) || |
||
| 111 | (preg_match('#(' . $sigContent . ')#smi', $normalized, $found, PREG_OFFSET_CAPTURE)) |
||
| 112 | ) { |
||
| 113 | $detected = true; |
||
| 114 | $pos = $found[0][1]; |
||
| 115 | $this->infected[$path][] = [ |
||
| 116 | 'pos' => (int)$pos, |
||
| 117 | 'sigId' => $attrId, |
||
| 118 | 'sigRule' => $sigContent, |
||
| 119 | 'sever' => $attrSever, |
||
| 120 | 'title' => $attrTitle |
||
| 121 | ]; |
||
| 122 | } |
||
| 123 | |||
| 124 | break; |
||
| 125 | case 'const': |
||
| 126 | if ((($pos = strpos($content, $sigContent)) !== false) || |
||
| 127 | (($pos = strpos($normalized, $sigContent)) !== false) |
||
| 128 | ) { |
||
| 129 | $this->infected[$path][] = [ |
||
| 130 | 'pos' => (int)$pos, |
||
| 131 | 'sigId' => $attrId, |
||
| 132 | 'sigRule' => $sigContent, |
||
| 133 | 'sever' => $attrSever, |
||
| 134 | 'title' => $attrTitle |
||
| 135 | ]; |
||
| 136 | $detected = true; |
||
| 137 | } |
||
| 138 | |||
| 139 | break; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | return $detected; |
||
| 143 | } |
||
| 169 |