Skip to content

Commit

Permalink
Some minor codebase fixes and improvements
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed May 24, 2020
1 parent 0a6a316 commit 6d123fe
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 66 deletions.
6 changes: 3 additions & 3 deletions libraries/classes/Config/FormDisplay.php
Expand Up @@ -588,12 +588,12 @@ public function fixErrors()
/**
* Validates select field and casts $value to correct type
*
* @param string $value Current value
* @param array $allowed List of allowed values
* @param string|bool $value Current value
* @param array $allowed List of allowed values
*
* @return bool
*/
private function _validateSelect(&$value, array $allowed)
private function _validateSelect(&$value, array $allowed): bool
{
$valueCmp = is_bool($value)
? (int) $value
Expand Down
8 changes: 4 additions & 4 deletions libraries/classes/Config/ServerConfigChecks.php
Expand Up @@ -237,17 +237,17 @@ protected function performConfigChecksServers(
/**
* Set blowfish secret
*
* @param string $blowfishSecret Blowfish secret
* @param bool $cookieAuthServer Cookie auth is used
* @param bool $blowfishSecretSet Blowfish secret set
* @param string|null $blowfishSecret Blowfish secret
* @param bool $cookieAuthServer Cookie auth is used
* @param bool $blowfishSecretSet Blowfish secret set
*
* @return array
*/
protected function performConfigChecksServersSetBlowfishSecret(
$blowfishSecret,
$cookieAuthServer,
$blowfishSecretSet
) {
): array {
if ($cookieAuthServer && $blowfishSecret === null) {
$blowfishSecretSet = true;
$this->cfg->set('blowfish_secret', Util::generateRandom(32));
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/Controllers/Server/VariablesController.php
Expand Up @@ -215,12 +215,12 @@ public function setValue(array $vars): void
/**
* Format Variable
*
* @param string $name variable name
* @param int $value variable value
* @param string $name variable name
* @param int|string $value variable value
*
* @return array formatted string and bool if string is HTML formatted
*/
private function formatVariable($name, $value)
private function formatVariable($name, $value): array
{
$isHtmlFormatted = false;
$formattedValue = $value;
Expand Down
9 changes: 4 additions & 5 deletions libraries/classes/Controllers/Table/StructureController.php
Expand Up @@ -658,15 +658,14 @@ public function moveColumns(): void
$data = $columns[$column];
$extracted_columnspec = Util::extractColumnSpec($data['Type']);
if (isset($data['Extra'])
&& $data['Extra'] == 'on update CURRENT_TIMESTAMP'
&& $data['Extra'] === 'on update CURRENT_TIMESTAMP'
) {
$extracted_columnspec['attribute'] = $data['Extra'];
unset($data['Extra']);
}
$current_timestamp = ($data['Type'] == 'timestamp'
|| $data['Type'] == 'datetime')
&& ($data['Default'] == 'CURRENT_TIMESTAMP'
|| $data['Default'] == 'current_timestamp()');
$timeType = $data['Type'] === 'timestamp' || $data['Type'] === 'datetime';
$timeDefault = $data['Default'] === 'CURRENT_TIMESTAMP' || $data['Default'] === 'current_timestamp()';
$current_timestamp = $timeType && $timeDefault;

// @see https://mariadb.com/kb/en/library/information-schema-columns-table/#examples
if ($data['Null'] === 'YES' && in_array($data['Default'], [$defaultNullValue, null])) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Export.php
Expand Up @@ -437,7 +437,7 @@ public function openFile(string $filename, bool $quick_export): array
} else {
$file_handle = @fopen($save_filename, 'w');

if (! $file_handle) {
if ($file_handle === false) {
$message = Message::error(
__(
'The web server does not have permission '
Expand Down
26 changes: 13 additions & 13 deletions libraries/classes/Sql.php
Expand Up @@ -1351,7 +1351,7 @@ private function getQueryResponseForNoResultsReturned(
true
);

if (is_array($profiling_results)) {
if ($profiling_results !== null) {
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('sql.js');
Expand Down Expand Up @@ -1424,18 +1424,18 @@ private function getBookmarkCreatedMessage(): string
/**
* Function to get html for the sql query results table
*
* @param DisplayResults $displayResultsObject instance of DisplayResult
* @param string $pmaThemeImage theme image uri
* @param string $url_query url query
* @param array $displayParts the parts to display
* @param bool $editable whether the result table is
* editable or not
* @param int $unlim_num_rows unlimited number of rows
* @param int $num_rows number of rows
* @param bool $showtable whether to show table or not
* @param object|null $result result of the executed query
* @param array $analyzed_sql_results analyzed sql results
* @param bool $is_limited_display Show only limited operations or not
* @param DisplayResults $displayResultsObject instance of DisplayResult
* @param string $pmaThemeImage theme image uri
* @param string $url_query url query
* @param array $displayParts the parts to display
* @param bool $editable whether the result table is
* editable or not
* @param int $unlim_num_rows unlimited number of rows
* @param int $num_rows number of rows
* @param bool $showtable whether to show table or not
* @param object|null|bool $result result of the executed query
* @param array $analyzed_sql_results analyzed sql results
* @param bool $is_limited_display Show only limited operations or not
*
* @return string
*/
Expand Down
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Expand Up @@ -205,11 +205,6 @@ parameters:
count: 2
path: libraries/classes/Config/FormDisplay.php

-
message: "#^Call to function is_bool\\(\\) with string will always evaluate to false\\.$#"
count: 2
path: libraries/classes/Config/FormDisplay.php

-
message: "#^Parameter \\#2 \\$type of function settype expects string, string\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -240,16 +235,6 @@ parameters:
count: 1
path: libraries/classes/Config/Forms/BaseFormList.php

-
message: "#^Result of && is always false\\.$#"
count: 1
path: libraries/classes/Config/ServerConfigChecks.php

-
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
count: 1
path: libraries/classes/Config/ServerConfigChecks.php

-
message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, string given\\.$#"
count: 1
Expand Down Expand Up @@ -3860,16 +3845,6 @@ parameters:
count: 1
path: libraries/classes/Sql.php

-
message: "#^Call to function is_bool\\(\\) with object will always evaluate to false\\.$#"
count: 1
path: libraries/classes/Sql.php

-
message: "#^Call to function is_bool\\(\\) with object\\|null will always evaluate to false\\.$#"
count: 1
path: libraries/classes/Sql.php

-
message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\Sql\\:\\:sendResponseForGridEdit\\(\\) expects object, object\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -4560,11 +4535,6 @@ parameters:
count: 1
path: test/classes/ErrorHandlerTest.php

-
message: "#^Parameter \\#1 \\$input of function array_values expects array, array\\|bool given\\.$#"
count: 1
path: test/classes/FileListingTest.php

-
message: "#^Parameter \\#1 \\$data of function bin2hex expects string, string\\|false given\\.$#"
count: 1
Expand Down
13 changes: 7 additions & 6 deletions psalm-baseline.xml
Expand Up @@ -114,11 +114,10 @@
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="libraries/classes/Config/FormDisplay.php">
<PossiblyFalseArgument occurrences="5">
<PossiblyFalseArgument occurrences="4">
<code>$workPath</code>
<code>$workPath</code>
<code>$_POST[$key]</code>
<code>$_POST[$key]</code>
<code>$workPath</code>
</PossiblyFalseArgument>
<PossiblyFalseIterator occurrences="1">
Expand Down Expand Up @@ -2353,10 +2352,11 @@
</PossiblyNullArgument>
</file>
<file src="libraries/classes/Sql.php">
<InvalidArgument occurrences="3">
<InvalidArgument occurrences="4">
<code>$showtable</code>
<code>$showtable</code>
<code>$result</code>
<code>$result</code>
</InvalidArgument>
<InvalidScalarArgument occurrences="3">
<code>''</code>
Expand All @@ -2367,10 +2367,12 @@
<code>save</code>
<code>save</code>
</PossiblyFalseReference>
<PossiblyInvalidArgument occurrences="5">
<PossiblyInvalidArgument occurrences="7">
<code>$cfgBookmark</code>
<code>$result</code>
<code>$fields_meta</code>
<code>$result</code>
<code>$result</code>
<code>$fields_meta</code>
<code>$cfgBookmark</code>
</PossiblyInvalidArgument>
Expand All @@ -2379,7 +2381,7 @@
<code>$cfgBookmark['user']</code>
<code>$cfgBookmark['user']</code>
</PossiblyInvalidArrayAccess>
<PossiblyNullArgument occurrences="28">
<PossiblyNullArgument occurrences="27">
<code>$db</code>
<code>$table</code>
<code>$db</code>
Expand All @@ -2391,7 +2393,6 @@
<code>$printview</code>
<code>$printview</code>
<code>$result</code>
<code>$result</code>
<code>$url_query</code>
<code>$showtable</code>
<code>$sql_data ?? null</code>
Expand Down
6 changes: 5 additions & 1 deletion test/classes/FileListingTest.php
Expand Up @@ -27,12 +27,16 @@ public function testGetDirContent(): void

$fixturesDir = ROOT_PATH . 'test/classes/_data/file_listing';

$dirContent = $this->fileListing->getDirContent($fixturesDir);
if (is_bool($dirContent)) {
$dirContent = [];
}
$this->assertSame(
array_values([
'one.txt',
'two.md',
]),
array_values($this->fileListing->getDirContent($fixturesDir))
array_values($dirContent)
);
}

Expand Down

0 comments on commit 6d123fe

Please sign in to comment.