Skip to content

Commit d7bb582

Browse files
committed
small refactor
fix travis version for L5.3
1 parent 36be1df commit d7bb582

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ before_install:
4949
- if [[ $LARAVEL_VERSION == '5.3' ]]; then composer create-project laravel/laravel:$LARAVEL_VERSION --stability dev; fi
5050
- composer update
5151
- cd ./laravel
52-
- composer require padosoft/laravel-test:1.1.*
52+
- composer require padosoft/laravel-test:1.*
5353
- composer require padosoft/test:0.1.*
5454
- composer require padosoft/laravel-composer-security dev-master
5555
- if [[ $LARAVEL_VERSION == '5.0' ]]; then composer require mockery/mockery; fi

src/ComposerSecurityCheck.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,27 @@ private function hardWork($argument, $option)
111111
*/
112112
private function notifyResult($mail, $nomailok, $tuttoOk)
113113
{
114-
115114
//print to console
116115
$this->table($this->headersTableConsole, $this->tableVulnerabilities);
117116

118-
$nomailok_bool = false;
119-
120-
if ($nomailok!='' && strtolower($nomailok)=='true') {
121-
$nomailok_bool = true;
122-
}
123-
124117
//send email
125-
if(!$nomailok_bool || !$tuttoOk) {
118+
if (!$tuttoOk || $nomailok == '' || strtolower($nomailok) != 'true') {
126119
$this->sendEmail($mail, $tuttoOk);
127120
}
128121

129-
if ($tuttoOk) {
122+
$this->notify($tuttoOk);
123+
}
124+
125+
126+
private function notify($result)
127+
{
128+
if ($result) {
130129
return $this->notifyOK();
131130
}
132131

133132
$this->notifyKO();
134133
}
135134

136-
137135
private function notifyOK()
138136
{
139137
$esito = Config::get('composer-security-check.mailSubjectSuccess');
@@ -168,11 +166,11 @@ private function findFilesComposerLock($path)
168166
$file = new FileHelper();
169167
$lockFiles = array();
170168
foreach ($file->adjustPath($path) as $item) {
171-
$lockFiles = array_merge($lockFiles,$file->findFiles($item, 'composer.lock'));
169+
$lockFiles = array_merge($lockFiles, $file->findFiles($item, 'composer.lock'));
172170
}
173171

174172

175-
if(!is_array($lockFiles)){
173+
if (!is_array($lockFiles)) {
176174
$lockFiles = array();
177175
}
178176

@@ -211,7 +209,8 @@ private function checkFile($fileLock, $whitelist)
211209

212210
foreach ($response as $key => $vulnerability) {
213211

214-
$this->tableVulnerabilities = array_merge($this->tableVulnerabilities, $sensiolab->checkResponse($key, $vulnerability, $tuttoOk));
212+
$this->tableVulnerabilities = array_merge($this->tableVulnerabilities,
213+
$sensiolab->checkResponse($key, $vulnerability, $tuttoOk));
215214
}
216215

217216
return $tuttoOk;

src/SensiolabHelper.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public function getSensiolabVulnerabilties($fileLock)
7979
$this->command->error("ClientException!\nMessage: " . $e->getMessage());
8080
$colorTag = $this->getColorTagForStatusCode($e->getResponse()->getStatusCode());
8181
$this->command->line("HTTP StatusCode: <{$colorTag}>" . $e->getResponse()->getStatusCode() . "<{$colorTag}>");
82-
$this->printMessage($e->getResponse());
82+
$this->printMessage($e->getResponse() === null ? '' : $e->getResponse());
8383
$this->printMessage($e->getRequest());
8484
} catch (\GuzzleHttp\Exception\RequestException $e) {
8585
$this->command->error("RequestException!\nMessage: " . $e->getMessage());
8686
$this->printMessage($e->getRequest());
8787
if ($e->hasResponse()) {
8888
$colorTag = $this->getColorTagForStatusCode($e->getResponse()->getStatusCode());
8989
$this->command->line("HTTP StatusCode: <{$colorTag}>" . $e->getResponse()->getStatusCode() . "<{$colorTag}>");
90-
$this->printMessage($e->getResponse());
90+
$this->printMessage($e->getResponse() === null ? '' : $e->getResponse());
9191
}
9292
}
9393
return $response;
@@ -162,14 +162,19 @@ private function addVerboseLog($msg, $error = false)
162162
/**
163163
* @param \Psr\Http\Message\MessageInterface $message
164164
*
165+
* @throws \RuntimeException
165166
*/
166167
private function printMessage(\Psr\Http\Message\MessageInterface $message)
167168
{
168169
$type = '';
169170
if (is_a($message, '\Psr\Http\Message\RequestInterface')) {
170171
$type = 'REQUEST';
171-
} else if (is_a($message, '\Psr\Http\Message\ResponseInterface')) {
172-
$type = 'RESPONSE';
172+
$body = $message->getBody();
173+
} else {
174+
if (is_a($message, '\Psr\Http\Message\ResponseInterface')) {
175+
$type = 'RESPONSE';
176+
$body = $message->getBody()->getContents();
177+
}
173178
}
174179
$this->command->info("$type:");
175180
$headers = '';
@@ -178,9 +183,11 @@ private function printMessage(\Psr\Http\Message\MessageInterface $message)
178183
}
179184
$this->command->comment($headers);
180185
if ($type == 'REQUEST') {
181-
$this->command->comment($message->getBody());
182-
} else if ($type == 'RESPONSE') {
183-
$this->command->comment($message->getBody()->getContents());
186+
$this->command->comment($body);
187+
} else {
188+
if ($type == 'RESPONSE') {
189+
$this->command->comment($body);
190+
}
184191
}
185192
}
186193

0 commit comments

Comments
 (0)