Conditions | 15 |
Paths | 23 |
Total Lines | 57 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
65 | public function parseResponse($rawResponse, $result = null){ |
||
66 | $matches = array(); |
||
67 | $ruleMapper = new Db\RuleMapper(\OC::$server->getDb()); |
||
68 | if (is_null($result)){ // Daemon or socket mode |
||
69 | try{ |
||
70 | $allRules = $this->getResponseRules(); |
||
71 | } catch (\Exception $e){ |
||
72 | \OCP\Util::writeLog('files_antivirus', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR); |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $isMatched = false; |
||
77 | foreach ($allRules as $rule){ |
||
78 | if (preg_match($rule->getMatch(), $rawResponse, $matches)){ |
||
79 | $isMatched = true; |
||
80 | $this->numericStatus = $rule->getStatus(); |
||
81 | if (intval($rule->getStatus())===self::SCANRESULT_CLEAN){ |
||
82 | $this->details = ''; |
||
83 | } else { |
||
84 | $this->details = isset($matches[1]) ? $matches[1] : 'unknown'; |
||
85 | } |
||
86 | break; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | if (!$isMatched){ |
||
91 | $this->numericStatus = self::SCANRESULT_UNCHECKED; |
||
92 | $this->details = 'No matching rules. Please check antivirus rules.'; |
||
93 | } |
||
94 | |||
95 | } else { // Executable mode |
||
96 | $scanStatus = $ruleMapper->findByResult($result); |
||
97 | if (is_array($scanStatus) && count($scanStatus)){ |
||
98 | $this->numericStatus = $scanStatus[0]->getStatus(); |
||
99 | $this->details = $scanStatus[0]->getDescription(); |
||
100 | } |
||
101 | |||
102 | switch($this->numericStatus) { |
||
103 | case self::SCANRESULT_INFECTED: |
||
104 | $report = array(); |
||
105 | $rawResponse = explode("\n", $rawResponse); |
||
106 | |||
107 | foreach ($rawResponse as $line){ |
||
108 | if (preg_match('/.*: (.*) FOUND\s*$/', $line, $matches)) { |
||
109 | $report[] = $matches[1]; |
||
110 | } |
||
111 | } |
||
112 | $this->details = implode(', ', $report); |
||
113 | |||
114 | break; |
||
115 | case self::SCANRESULT_UNCHECKED: |
||
116 | if (!$this->details) { |
||
117 | $this->details = 'No matching rule for exit code ' . $this->numericStatus .'. Please check antivirus rules configuration.' ; |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | |||
151 |