diff options
author | William Desportes <williamdes@wdes.fr> | 2018-10-07 23:30:09 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2018-11-25 15:57:57 +0300 |
commit | cc2665121d8931b702c08ff12182cde9c452ee43 (patch) | |
tree | aaed934f64b2f9254cf2eab81d206baacb652c6d | |
parent | ca8a424ed8d7035ae87918a3378a5d4eed08b0b6 (diff) |
phpstan level 2 - fixes
Signed-off-by: William Desportes <williamdes@wdes.fr>
29 files changed, 85 insertions, 70 deletions
diff --git a/export.php b/export.php index d002b6b46e..cd8b882616 100644 --- a/export.php +++ b/export.php @@ -192,7 +192,7 @@ PhpMyAdmin\Util::checkParameters(['what', 'export_type']); $what = Core::securePath($_POST['what']); // export class instance, not array of properties, as before -/* @var $export_plugin ExportPlugin */ +/** @var ExportPlugin $export_plugin */ $export_plugin = Plugins::getPlugin( "export", $what, diff --git a/import.php b/import.php index e3b9bdbe05..c5388168cc 100644 --- a/import.php +++ b/import.php @@ -537,7 +537,9 @@ if (! $error && isset($_POST['skip'])) { $sql_data = ['valid_sql' => [], 'valid_queries' => 0]; if (! $error) { - /* @var $import_plugin ImportPlugin */ + /** + * @var ImportPlugin $import_plugin + */ $import_plugin = Plugins::getPlugin( "import", $format, diff --git a/libraries/classes/CentralColumns.php b/libraries/classes/CentralColumns.php index 6b24a24cf5..e4f38273fa 100644 --- a/libraries/classes/CentralColumns.php +++ b/libraries/classes/CentralColumns.php @@ -1048,14 +1048,14 @@ class CentralColumns * @param int $from starting offset of first result * @param int $num maximum number of results to return * - * @return array list of $num columns present in central columns list + * @return int count of $num columns present in central columns list * starting at offset $from for the given database */ public function getColumnsCount(string $db, int $from = 0, int $num = 25): int { $cfgCentralColumns = $this->getParams(); if (empty($cfgCentralColumns)) { - return []; + return 0; } $pmadb = $cfgCentralColumns['db']; $this->dbi->selectDb($pmadb, DatabaseInterface::CONNECT_CONTROL); diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php index 8c4b562d05..09dbac723c 100644 --- a/libraries/classes/Config.php +++ b/libraries/classes/Config.php @@ -718,7 +718,7 @@ class Config } } while ($dataline != ''); $message = trim(implode(' ', $commit)); - } elseif (isset($commit_json) && isset($commit_json->author) && isset($commit_json->committer)) { + } elseif (isset($commit_json) && isset($commit_json->author) && isset($commit_json->committer) && isset($commit_json->message)) { $author = [ 'name' => $commit_json->author->name, 'email' => $commit_json->author->email, diff --git a/libraries/classes/Config/PageSettings.php b/libraries/classes/Config/PageSettings.php index ef21cb0101..a821536852 100644 --- a/libraries/classes/Config/PageSettings.php +++ b/libraries/classes/Config/PageSettings.php @@ -113,7 +113,7 @@ class PageSettings // reload page $response = Response::getInstance(); Core::sendHeaderLocation( - $response->getFooter()->getSelfUrl('unencoded') + $response->getFooter()->getSelfUrl() ); exit(); } else { diff --git a/libraries/classes/Controllers/Table/TableChartController.php b/libraries/classes/Controllers/Table/TableChartController.php index 4abceb090b..f063c2e007 100644 --- a/libraries/classes/Controllers/Table/TableChartController.php +++ b/libraries/classes/Controllers/Table/TableChartController.php @@ -13,6 +13,7 @@ use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Message; use PhpMyAdmin\Response; use PhpMyAdmin\SqlParser\Components\Limit; +use PhpMyAdmin\SqlParser\Statements\SelectStatement; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\Table; use PhpMyAdmin\Template; @@ -209,6 +210,9 @@ class TableChartController extends TableController } $parser = new Parser($this->sql_query); + /** + * @var SelectStatement $statement + */ $statement = $parser->statements[0]; if (empty($statement->limit)) { $statement->limit = new Limit( diff --git a/libraries/classes/Dbi/DbiMysqli.php b/libraries/classes/Dbi/DbiMysqli.php index 1ec1a9187c..b5e6e7a5b1 100644 --- a/libraries/classes/Dbi/DbiMysqli.php +++ b/libraries/classes/Dbi/DbiMysqli.php @@ -498,6 +498,7 @@ class DbiMysqli implements DbiExtension */ public function fieldLen($result, $i) { + /** @var \stdClass $fieldDefinition */ $fieldDefinition = $result->fetch_field_direct($i); if ($fieldDefinition !== false) { return $fieldDefinition->length; @@ -515,6 +516,7 @@ class DbiMysqli implements DbiExtension */ public function fieldName($result, $i) { + /** @var \stdClass $fieldDefinition */ $fieldDefinition = $result->fetch_field_direct($i); if ($fieldDefinition !== false) { return $fieldDefinition->name; @@ -532,30 +534,35 @@ class DbiMysqli implements DbiExtension */ public function fieldFlags($result, $i) { + /** @var \stdClass $fieldDefinition */ $fieldDefinition = $result->fetch_field_direct($i); - $type = $fieldDefinition->type; - $charsetNumber = $fieldDefinition->charsetnr; - $fieldDefinitionFlags = $fieldDefinition->flags; - $flags = []; - foreach (self::$pma_mysqli_flag_names as $flag => $name) { - if ($fieldDefinitionFlags & $flag) { - $flags[] = $name; + if ($fieldDefinition !== false) { + $type = $fieldDefinition->type; + $charsetNumber = $fieldDefinition->charsetnr; + $fieldDefinitionFlags = $fieldDefinition->flags; + $flags = []; + foreach (self::$pma_mysqli_flag_names as $flag => $name) { + if ($fieldDefinitionFlags & $flag) { + $flags[] = $name; + } } + // See https://dev.mysql.com/doc/refman/6.0/en/c-api-datatypes.html: + // to determine if a string is binary, we should not use MYSQLI_BINARY_FLAG + // but instead the charsetnr member of the MYSQL_FIELD + // structure. Watch out: some types like DATE returns 63 in charsetnr + // so we have to check also the type. + // Unfortunately there is no equivalent in the mysql extension. + if (($type == MYSQLI_TYPE_TINY_BLOB || $type == MYSQLI_TYPE_BLOB + || $type == MYSQLI_TYPE_MEDIUM_BLOB || $type == MYSQLI_TYPE_LONG_BLOB + || $type == MYSQLI_TYPE_VAR_STRING || $type == MYSQLI_TYPE_STRING) + && 63 == $charsetNumber + ) { + $flags[] = 'binary'; + } + return implode(' ', $flags); + } else { + return ''; } - // See https://dev.mysql.com/doc/refman/6.0/en/c-api-datatypes.html: - // to determine if a string is binary, we should not use MYSQLI_BINARY_FLAG - // but instead the charsetnr member of the MYSQL_FIELD - // structure. Watch out: some types like DATE returns 63 in charsetnr - // so we have to check also the type. - // Unfortunately there is no equivalent in the mysql extension. - if (($type == MYSQLI_TYPE_TINY_BLOB || $type == MYSQLI_TYPE_BLOB - || $type == MYSQLI_TYPE_MEDIUM_BLOB || $type == MYSQLI_TYPE_LONG_BLOB - || $type == MYSQLI_TYPE_VAR_STRING || $type == MYSQLI_TYPE_STRING) - && 63 == $charsetNumber - ) { - $flags[] = 'binary'; - } - return implode(' ', $flags); } /** diff --git a/libraries/classes/Di/ReflectorItem.php b/libraries/classes/Di/ReflectorItem.php index 8277543076..0071816511 100644 --- a/libraries/classes/Di/ReflectorItem.php +++ b/libraries/classes/Di/ReflectorItem.php @@ -20,7 +20,10 @@ abstract class ReflectorItem implements Item /** @var Container */ private $_container; - /** @var \Reflector */ + /** + * A \Reflector + * @var \ReflectionClass|\ReflectionMethod|\ReflectionFunction + */ private $_reflector; /** @@ -74,7 +77,7 @@ abstract class ReflectorItem implements Item * @param \ReflectionParameter[] $required Arguments * @param array $params Parameters * -*@return array + * @return array */ private function _resolveArgs($required, array $params = []) { diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 4022db6942..735d0cfb13 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -1202,7 +1202,7 @@ class Export $export_type = Core::securePath($export_type); // get the specific plugin - /* @var $export_plugin SchemaPlugin */ + /** @var \PhpMyAdmin\Plugins\SchemaPlugin $export_plugin */ $export_plugin = Plugins::getPlugin( "schema", $export_type, @@ -1210,7 +1210,7 @@ class Export ); // Check schema export type - if (! isset($export_plugin)) { + if (is_null($export_plugin) || ! is_object($export_plugin)) { Core::fatalError(__('Bad type!')); } diff --git a/libraries/classes/Gis/GisFactory.php b/libraries/classes/Gis/GisFactory.php index bbf225dcda..353d7e62bf 100644 --- a/libraries/classes/Gis/GisFactory.php +++ b/libraries/classes/Gis/GisFactory.php @@ -21,8 +21,7 @@ class GisFactory * * @param string $type type of the geometric object * - * @return GisGeometry the singleton instance of geometric class - * of the given type + * @return GisMultiPolygon|GisPolygon|GisMultiPoint|GisPoint|GisMultiLineString|GisLineString|GisGeometryCollection|false the singleton instance of geometric class of the given type * * @access public * @static diff --git a/libraries/classes/Gis/GisGeometryCollection.php b/libraries/classes/Gis/GisGeometryCollection.php index 618fc13989..a777ae4931 100644 --- a/libraries/classes/Gis/GisGeometryCollection.php +++ b/libraries/classes/Gis/GisGeometryCollection.php @@ -404,6 +404,9 @@ class GisGeometryCollection extends GisGeometry continue; } $type = mb_substr($sub_part, 0, $type_pos); + /** + * @var GisMultiPolygon|GisPolygon|GisMultiPoint|GisPoint|GisMultiLineString|GisLineString $gis_obj + */ $gis_obj = GisFactory::factory($type); if (!$gis_obj) { continue; diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index c3ee295191..deca71156c 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -2413,7 +2413,7 @@ class InsertEdit DatabaseInterface::QUERY_STORE ); if ($dispresult && $this->dbi->numRows($dispresult) > 0) { - list($dispval) = $this->dbi->fetchRow($dispresult, 0); + list($dispval) = $this->dbi->fetchRow($dispresult); } else { $dispval = ''; } diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index 459eaf9e2a..c278431759 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -554,12 +554,7 @@ class AuthenticationCookie extends AuthenticationPlugin 'new_token', $_SESSION[' PMA_token '] ); - if($user_changed) { - $response->addJSON( - 'user_changed', - 1 - ); - } + if (! defined('TESTSUITE')) { exit; } else { diff --git a/libraries/classes/Plugins/Schema/Dia/RelationStatsDia.php b/libraries/classes/Plugins/Schema/Dia/RelationStatsDia.php index 8e17531b48..c00fd34e41 100644 --- a/libraries/classes/Plugins/Schema/Dia/RelationStatsDia.php +++ b/libraries/classes/Plugins/Schema/Dia/RelationStatsDia.php @@ -40,11 +40,11 @@ class RelationStatsDia /** * The "PhpMyAdmin\Plugins\Schema\Dia\RelationStatsDia" constructor * - * @param Dia $diagram The DIA diagram - * @param string $master_table The master table name - * @param string $master_field The relation field in the master table - * @param string $foreign_table The foreign table name - * @param string $foreign_field The relation field in the foreign table + * @param Dia $diagram The DIA diagram + * @param TableStatsDia $master_table The master table name + * @param string $master_field The relation field in the master table + * @param TableStatsDia $foreign_table The foreign table name + * @param string $foreign_field The relation field in the foreign table * * @see Relation_Stats_Dia::_getXy */ @@ -75,8 +75,8 @@ class RelationStatsDia * then determines its left and right connection * points. * - * @param string $table The current table name - * @param string $column The relation column name + * @param TableStatsDia $table The current table name + * @param string $column The relation column name * * @return array Table right,left connection points and key position * diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 3eb0806b7e..370bf34d34 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -1897,7 +1897,7 @@ class Privileges ); // Table 'mysql'.'user' may not exist for some previous // versions of MySQL - in that case consider fallback value - if (isset($row) && $row) { + if (is_array($row) && isset($row['plugin'])) { $authentication_plugin = $row['plugin']; } } elseif ($mode == 'change') { @@ -1907,7 +1907,7 @@ class Privileges 'SELECT `plugin` FROM `mysql`.`user` WHERE ' . '`User` = "' . $username . '" AND `Host` = "' . $hostname . '"' ); - if (isset($row) && $row && ! empty($row['plugin'])) { + if (is_array($row) && isset($row['plugin'])) { $authentication_plugin = $row['plugin']; } } elseif ($serverVersion >= 50702) { diff --git a/libraries/classes/SysInfo.php b/libraries/classes/SysInfo.php index 7501b059bf..a474f38f66 100644 --- a/libraries/classes/SysInfo.php +++ b/libraries/classes/SysInfo.php @@ -45,7 +45,7 @@ class SysInfo /** * Gets sysinfo class mathing current OS * - * @return PhpMyAdmin\SysInfoBase|mixed sysinfo class + * @return SysInfoBase sysinfo class */ public static function get() { @@ -54,7 +54,7 @@ class SysInfo if (in_array($php_os, $supported)) { $class_name = 'PhpMyAdmin\SysInfo' . $php_os; - /** @var PhpMyAdmin\SysInfoBase $ret */ + /** @var SysInfoBase $ret */ $ret = new $class_name(); if ($ret->supported()) { return $ret; diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index 8d42053c49..92335e0f82 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -1005,7 +1005,7 @@ class Table /** * Instance used for exporting the current structure of the table. * - * @var PhpMyAdmin\Plugins\Export\ExportSql + * @var ExportSql $export_sql_plugin */ $export_sql_plugin = Plugins::getPlugin( "export", diff --git a/libraries/classes/ThemeManager.php b/libraries/classes/ThemeManager.php index d2649d16da..ed1318b5f1 100644 --- a/libraries/classes/ThemeManager.php +++ b/libraries/classes/ThemeManager.php @@ -119,11 +119,11 @@ class ThemeManager } /** - * Returns the singleton Response object + * Returns the singleton ThemeManager object * - * @return ThemeManager object + * @return ThemeManager The instance */ - public static function getInstance() + public static function getInstance(): ThemeManager { if (empty(self::$_instance)) { self::$_instance = new ThemeManager(); diff --git a/libraries/classes/Tracking.php b/libraries/classes/Tracking.php index 912240d3d4..90f8e03e86 100644 --- a/libraries/classes/Tracking.php +++ b/libraries/classes/Tracking.php @@ -1170,7 +1170,7 @@ class Tracking * Get HTML for tracked and untracked tables * * @param string $db current database - * @param array $requestDb $_REQUEST['db'] + * @param string $requestDb $_REQUEST['db'] * @param string $urlQuery url query string * @param string $pmaThemeImage path to theme's image folder * @param string $textDir text direction diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index fd17626050..b16acd1c32 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1949,7 +1949,7 @@ class Util * * @param resource $handle current query result * @param integer $fields_cnt number of fields - * @param array $fields_meta meta information about fields + * @param \stdClass[] $fields_meta meta information about fields * @param array $row current row * @param boolean $force_unique generate condition only on pk * or unique diff --git a/server_binlog.php b/server_binlog.php index 10c0034d3f..3b55bc8606 100644 --- a/server_binlog.php +++ b/server_binlog.php @@ -24,7 +24,7 @@ $container->alias( $container->set('PhpMyAdmin\Response', Response::getInstance()); $container->alias('response', 'PhpMyAdmin\Response'); -/** @var ServerBinlogController $controller */ +/** @var \PhpMyAdmin\Controllers\Server\ServerBinlogController $controller */ $controller = $container->get( 'ServerBinlogController', [] diff --git a/setup/index.php b/setup/index.php index ad8ea2c894..ac7f542137 100644 --- a/setup/index.php +++ b/setup/index.php @@ -19,7 +19,7 @@ if (@file_exists(CONFIG_FILE) && ! $cfg['DBG']['demo']) { Core::fatalError(__('Configuration already exists, setup is disabled!')); } -$page = Core::isValid($_GET['page'], 'scalar') ? $_GET['page'] : null; +$page = Core::isValid($_GET['page'], 'scalar') ? (string) $_GET['page'] : null; $page = preg_replace('/[^a-z]/', '', $page); if ($page === '') { $page = 'index'; diff --git a/setup/lib/ConfigGenerator.php b/setup/lib/ConfigGenerator.php index d916e00a69..3ddd15d2c8 100644 --- a/setup/lib/ConfigGenerator.php +++ b/setup/lib/ConfigGenerator.php @@ -154,7 +154,7 @@ class ConfigGenerator * @param string $crlf Carriage return char * @param array $servers Servers list * - * @return string + * @return string|null */ protected static function getServerPart(ConfigFile $cf, $crlf, array $servers) { diff --git a/tbl_operations.php b/tbl_operations.php index a48c985313..717053a111 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -189,7 +189,7 @@ if (isset($_REQUEST['submitoptions'])) { . Util::backquote($GLOBALS['table']); $sql_query .= "\r\n" . implode("\r\n", $table_alters); $sql_query .= ';'; - $result .= $GLOBALS['dbi']->query($sql_query) ? true : false; + $result = $GLOBALS['dbi']->query($sql_query) ? true : false; $reread_info = true; unset($table_alters); $warning_messages = $operations->getWarningMessagesArray(); diff --git a/test/classes/Config/FormDisplayTest.php b/test/classes/Config/FormDisplayTest.php index e6f9ad7b53..a3ab932b67 100644 --- a/test/classes/Config/FormDisplayTest.php +++ b/test/classes/Config/FormDisplayTest.php @@ -211,9 +211,7 @@ class FormDisplayTest extends PmaTestCase $attrIsValidated->setAccessible(true); $attrIsValidated->setValue($this->object, []); - $this->assertNull( - $this->object->fixErrors() - ); + $this->object->fixErrors(); $arr = [ "Servers/1/test" => ['e1'], diff --git a/test/classes/ConfigTest.php b/test/classes/ConfigTest.php index eba39f394e..a0f3f5d87c 100644 --- a/test/classes/ConfigTest.php +++ b/test/classes/ConfigTest.php @@ -33,7 +33,7 @@ class ConfigTest extends PmaTestCase protected $object; /** - * @var object to test file permission + * @var Config to test file permission */ protected $permTestObj; @@ -719,10 +719,11 @@ class ConfigTest extends PmaTestCase * * @return void * @todo Test actually preferences loading + * @doesNotPerformAssertions */ public function testLoadUserPreferences() { - $this->assertNull($this->object->loadUserPreferences()); + $this->object->loadUserPreferences(); } /** diff --git a/test/classes/Navigation/Nodes/NodeDatabaseChildTest.php b/test/classes/Navigation/Nodes/NodeDatabaseChildTest.php index 2caacf2a76..fd8648b23a 100644 --- a/test/classes/Navigation/Nodes/NodeDatabaseChildTest.php +++ b/test/classes/Navigation/Nodes/NodeDatabaseChildTest.php @@ -21,7 +21,8 @@ use PhpMyAdmin\Tests\PmaTestCase; class NodeDatabaseChildTest extends PmaTestCase { /** - * @var NodeDatabaseChild + * Mock of NodeDatabaseChild + * @var \PHPUnit\Framework\MockObject\MockObject */ protected $object; diff --git a/test/classes/PmaTestCase.php b/test/classes/PmaTestCase.php index 6835f9eace..0aaaf433c5 100644 --- a/test/classes/PmaTestCase.php +++ b/test/classes/PmaTestCase.php @@ -25,7 +25,8 @@ class PmaTestCase extends TestCase */ protected $restoreInstance = null; /** - * @var Response + * class Response + * @var ReflectionProperty */ protected $attrInstance = null; diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 5b6ef48799..5067328434 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -12,6 +12,7 @@ namespace PhpMyAdmin\Tests\Selenium; use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; +use Facebook\WebDriver\Remote\RemoteWebElement; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Firefox\FirefoxDriver; use Facebook\WebDriver\Firefox\FirefoxProfile; @@ -758,11 +759,11 @@ abstract class TestBase extends TestCase * Wrapper around moveto method to not use it on not supported * browsers. * - * @param WebDriverElement $element element + * @param RemoteWebElement $element element * * @return void */ - public function moveto(WebDriverElement $element): void + public function moveto(RemoteWebElement $element): void { /** * Not supported in Safari Webdriver, see |