Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure variable declarations #4737

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ protected function _update(string $table, array $values): string
*/
protected function _updateBatch(string $table, array $values, string $index): string
{
$ids = [];
$ids = [];
$final = [];
foreach ($values as $val)
{
$ids[] = $val[$index];
Expand All @@ -319,13 +320,15 @@ protected function _updateBatch(string $table, array $values, string $index): st
{
if ($field !== $index)
{
$final[$field] = $final[$field] ?? [];

$final[$field][] = "WHEN {$val[$index]} THEN {$val[$field]}";
}
}
}

$cases = '';
foreach ($final as $k => $v) // @phpstan-ignore-line
foreach ($final as $k => $v)
{
$cases .= "{$k} = (CASE {$index}\n"
. implode("\n", $v)
Expand Down Expand Up @@ -383,11 +386,11 @@ protected function _truncate(string $table): string
*
* @see https://www.postgresql.org/docs/9.2/static/functions-matching.html
*
* @param string|null $prefix
* @param string $column
* @param string|null $not
* @param string $bind
* @param boolean $insensitiveSearch
* @param string|null $prefix
* @param string $column
* @param string|null $not
* @param string $bind
* @param boolean $insensitiveSearch
*
* @return string $like_statement
*/
Expand Down
15 changes: 10 additions & 5 deletions system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,8 @@ protected function buildMessage()
return;

case 'html':
$boundary = uniqid('B_ALT_', true);

if ($this->sendMultipart === false)
{
$hdr .= 'Content-Type: text/html; charset='
Expand All @@ -1280,8 +1282,6 @@ protected function buildMessage()
}
else
{
$boundary = uniqid('B_ALT_', true);

$hdr .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '"';
$body .= $this->getMimeMessage() . $this->newline . $this->newline
. '--' . $boundary . $this->newline
Expand All @@ -1306,7 +1306,7 @@ protected function buildMessage()

if ($this->sendMultipart !== false)
{
$this->finalBody .= '--' . $boundary . '--'; // @phpstan-ignore-line
$this->finalBody .= '--' . $boundary . '--';
}

return;
Expand Down Expand Up @@ -2184,13 +2184,16 @@ protected function sendCommand($cmd, $data = '')
$this->sendData('QUIT');
$resp = 221;
break;

default:
$resp = null;
}

$reply = $this->getSMTPData();

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

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

Expand Down Expand Up @@ -2278,6 +2281,8 @@ protected function sendData($data)
{
$data .= $this->newline;

$result = null;

for ($written = $timestamp = 0, $length = static::strlen($data); $written < $length; $written += $result)
{
if (($result = fwrite($this->SMTPConnect, static::substr($data, $written))) === false)
Expand Down Expand Up @@ -2307,7 +2312,7 @@ protected function sendData($data)
$timestamp = 0;
}

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

Expand Down
4 changes: 3 additions & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ function get_file_info(string $file, $returnedValues = ['name', 'server_path', '
return null;
}

$fileInfo = [];

if (is_string($returnedValues))
{
$returnedValues = explode(',', $returnedValues);
Expand Down Expand Up @@ -409,7 +411,7 @@ function get_file_info(string $file, $returnedValues = ['name', 'server_path', '
}
}

return $fileInfo; // @phpstan-ignore-line
return $fileInfo;
}
}

Expand Down
5 changes: 3 additions & 2 deletions system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ protected function process(string $action, int $quality = 100): array
$this->config->libraryPath = rtrim($this->config->libraryPath, '/') . '/convert';
}

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

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

return $output; // @phpstan-ignore-line
return $output;
}

//--------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion system/Log/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public function handle($level, $message): bool

flock($fp, LOCK_EX);

$result = null;

for ($written = 0, $length = strlen($msg); $written < $length; $written += $result)
{
if (($result = fwrite($fp, substr($msg, $written))) === false)
Expand All @@ -131,7 +133,7 @@ public function handle($level, $message): bool
chmod($filepath, $this->filePermissions);
}

return is_int($result); // @phpstan-ignore-line
return is_int($result);
}

//--------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public function write($sessionID, $sessionData): bool

if (($length = strlen($sessionData)) > 0)
{
$result = null;

for ($written = 0; $written < $length; $written += $result)
{
if (($result = fwrite($this->fileHandle, substr($sessionData, $written))) === false)
Expand All @@ -248,7 +250,7 @@ public function write($sessionID, $sessionData): bool
}
}

if (! is_int($result)) // @phpstan-ignore-line
if (! is_int($result))
{
$this->fingerprint = md5(substr($sessionData, 0, $written));
$this->logger->error('Session: Unable to write data.');
Expand Down
15 changes: 6 additions & 9 deletions system/View/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,13 @@ public function render(string $view, array $options = null, bool $saveData = nul
$fileExt = pathinfo($view, PATHINFO_EXTENSION);
$view = empty($fileExt) ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)

$cacheName = $options['cache_name'] ?? str_replace('.php', '', $view);

// Was it cached?
if (isset($options['cache']))
if (isset($options['cache']) && ($output = cache($cacheName)))
{
$cacheName = $options['cache_name'] ?? str_replace('.php', '', $view);

if ($output = cache($cacheName))
{
$this->logPerformance($start, microtime(true), $view);
return $output;
}
$this->logPerformance($start, microtime(true), $view);
return $output;
}

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