Skip to content

Commit be99e5e

Browse files
authored
Merge pull request #4737 from jeromegamez/variable-declarations
2 parents 6bacf2c + 53ef356 commit be99e5e

7 files changed

Lines changed: 38 additions & 26 deletions

File tree

system/Database/Postgre/Builder.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ protected function _update(string $table, array $values): string
310310
*/
311311
protected function _updateBatch(string $table, array $values, string $index): string
312312
{
313-
$ids = [];
313+
$ids = [];
314+
$final = [];
314315
foreach ($values as $val)
315316
{
316317
$ids[] = $val[$index];
@@ -319,13 +320,15 @@ protected function _updateBatch(string $table, array $values, string $index): st
319320
{
320321
if ($field !== $index)
321322
{
323+
$final[$field] = $final[$field] ?? [];
324+
322325
$final[$field][] = "WHEN {$val[$index]} THEN {$val[$field]}";
323326
}
324327
}
325328
}
326329

327330
$cases = '';
328-
foreach ($final as $k => $v) // @phpstan-ignore-line
331+
foreach ($final as $k => $v)
329332
{
330333
$cases .= "{$k} = (CASE {$index}\n"
331334
. implode("\n", $v)
@@ -383,11 +386,11 @@ protected function _truncate(string $table): string
383386
*
384387
* @see https://www.postgresql.org/docs/9.2/static/functions-matching.html
385388
*
386-
* @param string|null $prefix
387-
* @param string $column
388-
* @param string|null $not
389-
* @param string $bind
390-
* @param boolean $insensitiveSearch
389+
* @param string|null $prefix
390+
* @param string $column
391+
* @param string|null $not
392+
* @param string $bind
393+
* @param boolean $insensitiveSearch
391394
*
392395
* @return string $like_statement
393396
*/

system/Email/Email.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,8 @@ protected function buildMessage()
12721272
return;
12731273

12741274
case 'html':
1275+
$boundary = uniqid('B_ALT_', true);
1276+
12751277
if ($this->sendMultipart === false)
12761278
{
12771279
$hdr .= 'Content-Type: text/html; charset='
@@ -1280,8 +1282,6 @@ protected function buildMessage()
12801282
}
12811283
else
12821284
{
1283-
$boundary = uniqid('B_ALT_', true);
1284-
12851285
$hdr .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '"';
12861286
$body .= $this->getMimeMessage() . $this->newline . $this->newline
12871287
. '--' . $boundary . $this->newline
@@ -1306,7 +1306,7 @@ protected function buildMessage()
13061306

13071307
if ($this->sendMultipart !== false)
13081308
{
1309-
$this->finalBody .= '--' . $boundary . '--'; // @phpstan-ignore-line
1309+
$this->finalBody .= '--' . $boundary . '--';
13101310
}
13111311

13121312
return;
@@ -2184,13 +2184,16 @@ protected function sendCommand($cmd, $data = '')
21842184
$this->sendData('QUIT');
21852185
$resp = 221;
21862186
break;
2187+
2188+
default:
2189+
$resp = null;
21872190
}
21882191

21892192
$reply = $this->getSMTPData();
21902193

21912194
$this->debugMessage[] = '<pre>' . $cmd . ': ' . $reply . '</pre>';
21922195

2193-
if ((int) static::substr($reply, 0, 3) !== $resp) // @phpstan-ignore-line
2196+
if ($resp === null || ((int) static::substr($reply, 0, 3) !== $resp))
21942197
{
21952198
$this->setErrorMessage(lang('Email.SMTPError', [$reply]));
21962199

@@ -2278,6 +2281,8 @@ protected function sendData($data)
22782281
{
22792282
$data .= $this->newline;
22802283

2284+
$result = null;
2285+
22812286
for ($written = $timestamp = 0, $length = static::strlen($data); $written < $length; $written += $result)
22822287
{
22832288
if (($result = fwrite($this->SMTPConnect, static::substr($data, $written))) === false)
@@ -2307,7 +2312,7 @@ protected function sendData($data)
23072312
$timestamp = 0;
23082313
}
23092314

2310-
if ($result === false) // @phpstan-ignore-line
2315+
if (! is_int($result))
23112316
{
23122317
$this->setErrorMessage(lang('Email.SMTPDataFailure', [$data]));
23132318

system/Helpers/filesystem_helper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ function get_file_info(string $file, $returnedValues = ['name', 'server_path', '
374374
return null;
375375
}
376376

377+
$fileInfo = [];
378+
377379
if (is_string($returnedValues))
378380
{
379381
$returnedValues = explode(',', $returnedValues);
@@ -409,7 +411,7 @@ function get_file_info(string $file, $returnedValues = ['name', 'server_path', '
409411
}
410412
}
411413

412-
return $fileInfo; // @phpstan-ignore-line
414+
return $fileInfo;
413415
}
414416
}
415417

system/Images/Handlers/ImageMagickHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ protected function process(string $action, int $quality = 100): array
234234
$this->config->libraryPath = rtrim($this->config->libraryPath, '/') . '/convert';
235235
}
236236

237-
$cmd = $this->config->libraryPath;
237+
$cmd = $this->config->libraryPath;
238238
$cmd .= $action === '-version' ? ' ' . $action : ' -quality ' . $quality . ' ' . $action;
239239

240240
$retval = 1;
241+
$output = [];
241242
// exec() might be disabled
242243
if (function_usable('exec'))
243244
{
@@ -250,7 +251,7 @@ protected function process(string $action, int $quality = 100): array
250251
throw ImageException::forImageProcessFailed();
251252
}
252253

253-
return $output; // @phpstan-ignore-line
254+
return $output;
254255
}
255256

256257
//--------------------------------------------------------------------

system/Log/Handlers/FileHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function handle($level, $message): bool
112112

113113
flock($fp, LOCK_EX);
114114

115+
$result = null;
116+
115117
for ($written = 0, $length = strlen($msg); $written < $length; $written += $result)
116118
{
117119
if (($result = fwrite($fp, substr($msg, $written))) === false)
@@ -131,7 +133,7 @@ public function handle($level, $message): bool
131133
chmod($filepath, $this->filePermissions);
132134
}
133135

134-
return is_int($result); // @phpstan-ignore-line
136+
return is_int($result);
135137
}
136138

137139
//--------------------------------------------------------------------

system/Session/Handlers/FileHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ public function write($sessionID, $sessionData): bool
240240

241241
if (($length = strlen($sessionData)) > 0)
242242
{
243+
$result = null;
244+
243245
for ($written = 0; $written < $length; $written += $result)
244246
{
245247
if (($result = fwrite($this->fileHandle, substr($sessionData, $written))) === false)
@@ -248,7 +250,7 @@ public function write($sessionID, $sessionData): bool
248250
}
249251
}
250252

251-
if (! is_int($result)) // @phpstan-ignore-line
253+
if (! is_int($result))
252254
{
253255
$this->fingerprint = md5(substr($sessionData, 0, $written));
254256
$this->logger->error('Session: Unable to write data.');

system/View/Parser.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,13 @@ public function render(string $view, array $options = null, bool $saveData = nul
101101
$fileExt = pathinfo($view, PATHINFO_EXTENSION);
102102
$view = empty($fileExt) ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)
103103

104+
$cacheName = $options['cache_name'] ?? str_replace('.php', '', $view);
105+
104106
// Was it cached?
105-
if (isset($options['cache']))
107+
if (isset($options['cache']) && ($output = cache($cacheName)))
106108
{
107-
$cacheName = $options['cache_name'] ?? str_replace('.php', '', $view);
108-
109-
if ($output = cache($cacheName))
110-
{
111-
$this->logPerformance($start, microtime(true), $view);
112-
return $output;
113-
}
109+
$this->logPerformance($start, microtime(true), $view);
110+
return $output;
114111
}
115112

116113
$file = $this->viewPath . $view;
@@ -143,7 +140,7 @@ public function render(string $view, array $options = null, bool $saveData = nul
143140
// Should we cache?
144141
if (isset($options['cache']))
145142
{
146-
cache()->save($cacheName, $output, (int) $options['cache']); // @phpstan-ignore-line
143+
cache()->save($cacheName, $output, (int) $options['cache']);
147144
}
148145
$this->tempData = null;
149146
return $output;

0 commit comments

Comments
 (0)