| Conditions | 8 |
| Paths | 32 |
| Total Lines | 60 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 89 | */ |
||
| 90 | 2 | private function hardWork($argument,$option) |
|
| 91 | { |
||
| 92 | |||
| 93 | 2 | $this->line('path: <info>'.$argument['path'].'</info>.\nCheck composer.lock files...'); |
|
| 94 | 2 | $lockFiles = $this->findFilesComposerLock($argument['path']); |
|
| 95 | 2 | $this->line('Find <info>'.count($lockFiles).'</info> composer.lock files.'); |
|
| 96 | |||
| 97 | 2 | $this->tableVulnerabilities = []; |
|
| 98 | 2 | $tuttoOk = true; |
|
| 99 | 2 | $numLock=0; |
|
| 100 | |||
| 101 | //whitelist |
||
| 102 | |||
| 103 | 2 | $whitelist = $this->adjustWhiteList($option['whitelist']); |
|
| 104 | |||
| 105 | 2 | foreach ($lockFiles as $fileLock) { |
|
| 106 | 2 | $this->line("Analizing <info>".($numLock+1)."</info> di <info>".count($lockFiles)."</info>: $fileLock ..."); |
|
| 107 | 2 | $this->tableVulnerabilities[] = [ |
|
| 108 | 2 | 'name' => $fileLock, |
|
| 109 | 2 | 'version' => '', |
|
| 110 | 2 | 'advisories' => '', |
|
| 111 | 'isOk' => '' |
||
| 112 | 2 | ]; |
|
| 113 | |||
| 114 | 2 | $sensiolab = new SensiolabHelper($this->guzzle,$this); |
|
| 115 | 2 | $response = $sensiolab->getSensiolabVulnerabilties($fileLock); |
|
| 116 | |||
| 117 | 2 | if (($response==null) | !is_array($response)) { |
|
| 118 | $this->error("Errore Response not vaild or null."); |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | 2 | if (count($response)>0) { |
|
| 122 | 2 | $this->error("Trovate ".count($response)." vulnerabilita' in $fileLock"); |
|
| 123 | 2 | } |
|
| 124 | |||
| 125 | 2 | foreach ($response as $key => $vulnerability) { |
|
| 126 | 2 | $tuttoOk = in_array(rtrim(str_replace('\\','/',$fileLock),'composer.lock'),$whitelist); |
|
| 127 | |||
| 128 | 2 | foreach($sensiolab->parseVulnerability($key, $vulnerability) as $vul) { |
|
| 129 | 2 | $this->tableVulnerabilities[]=array_merge($vul,array('isOk'=>$tuttoOk)); |
|
| 130 | 2 | } |
|
| 131 | 2 | } |
|
| 132 | 2 | $numLock++; |
|
| 133 | 2 | } |
|
| 134 | |||
| 135 | 2 | $this->notifyResult($option['mail'],$tuttoOk); |
|
| 136 | |||
| 137 | 2 | } |
|
| 138 | |||
| 139 | 2 | private function adjustWhiteList($white) |
|
| 140 | { |
||
| 141 | 2 | $whitelist = array(); |
|
| 142 | 2 | if($white!='') { |
|
| 143 | 2 | $w = explode(",",str_replace('\\','/',$white)); |
|
| 144 | 2 | foreach($w as $item) { |
|
| 145 | 2 | $whitelist[] = str_finish($item,'/'); |
|
| 146 | 2 | } |
|
| 147 | 2 | } |
|
| 148 | 2 | return $whitelist; |
|
| 149 | } |
||
| 193 |