Skip to content

Commit

Permalink
phpstan level 2 - fixes
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Nov 25, 2018
1 parent ca8a424 commit cc26651
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 70 deletions.
2 changes: 1 addition & 1 deletion export.php
Expand Up @@ -192,7 +192,7 @@
$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,
Expand Down
4 changes: 3 additions & 1 deletion import.php
Expand Up @@ -537,7 +537,9 @@
$sql_data = ['valid_sql' => [], 'valid_queries' => 0];

if (! $error) {
/* @var $import_plugin ImportPlugin */
/**
* @var ImportPlugin $import_plugin
*/
$import_plugin = Plugins::getPlugin(
"import",
$format,
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/CentralColumns.php
Expand Up @@ -1048,14 +1048,14 @@ public function getHtmlForEditingPage(array $selected_fld, string $selected_db):
* @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);
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Config.php
Expand Up @@ -718,7 +718,7 @@ public function checkGitRevision(): void
}
} 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,
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Config/PageSettings.php
Expand Up @@ -113,7 +113,7 @@ private function _processPageSettings(&$formDisplay, &$cf, &$error)
// reload page
$response = Response::getInstance();
Core::sendHeaderLocation(
$response->getFooter()->getSelfUrl('unencoded')
$response->getFooter()->getSelfUrl()
);
exit();
} else {
Expand Down
4 changes: 4 additions & 0 deletions libraries/classes/Controllers/Table/TableChartController.php
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -209,6 +210,9 @@ public function ajaxAction()
}

$parser = new Parser($this->sql_query);
/**
* @var SelectStatement $statement
*/
$statement = $parser->statements[0];
if (empty($statement->limit)) {
$statement->limit = new Limit(
Expand Down
49 changes: 28 additions & 21 deletions libraries/classes/Dbi/DbiMysqli.php
Expand Up @@ -498,6 +498,7 @@ public function numFields($result)
*/
public function fieldLen($result, $i)
{
/** @var \stdClass $fieldDefinition */
$fieldDefinition = $result->fetch_field_direct($i);
if ($fieldDefinition !== false) {
return $fieldDefinition->length;
Expand All @@ -515,6 +516,7 @@ public function fieldLen($result, $i)
*/
public function fieldName($result, $i)
{
/** @var \stdClass $fieldDefinition */
$fieldDefinition = $result->fetch_field_direct($i);
if ($fieldDefinition !== false) {
return $fieldDefinition->name;
Expand All @@ -532,30 +534,35 @@ public function fieldName($result, $i)
*/
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);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions libraries/classes/Di/ReflectorItem.php
Expand Up @@ -20,7 +20,10 @@ abstract class ReflectorItem implements Item
/** @var Container */
private $_container;

/** @var \Reflector */
/**
* A \Reflector
* @var \ReflectionClass|\ReflectionMethod|\ReflectionFunction
*/
private $_reflector;

/**
Expand Down Expand Up @@ -74,7 +77,7 @@ protected function invoke(array $params = [])
* @param \ReflectionParameter[] $required Arguments
* @param array $params Parameters
*
*@return array
* @return array
*/
private function _resolveArgs($required, array $params = [])
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Export.php
Expand Up @@ -1202,15 +1202,15 @@ public function processExportSchema(?string $export_type): void
$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,
'libraries/classes/Plugins/Schema/'
);

// Check schema export type
if (! isset($export_plugin)) {
if (is_null($export_plugin) || ! is_object($export_plugin)) {
Core::fatalError(__('Bad type!'));
}

Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Gis/GisFactory.php
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libraries/classes/Gis/GisGeometryCollection.php
Expand Up @@ -404,6 +404,9 @@ public function generateParams($value)
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;
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/InsertEdit.php
Expand Up @@ -2413,7 +2413,7 @@ public function getDisplayValueForForeignTableColumn(
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 = '';
}
Expand Down
7 changes: 1 addition & 6 deletions libraries/classes/Plugins/Auth/AuthenticationCookie.php
Expand Up @@ -554,12 +554,7 @@ public function rememberCredentials()
'new_token',
$_SESSION[' PMA_token ']
);
if($user_changed) {
$response->addJSON(
'user_changed',
1
);
}

if (! defined('TESTSUITE')) {
exit;
} else {
Expand Down
14 changes: 7 additions & 7 deletions libraries/classes/Plugins/Schema/Dia/RelationStatsDia.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -75,8 +75,8 @@ public function __construct(
* 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
*
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Server/Privileges.php
Expand Up @@ -1897,7 +1897,7 @@ public function getCurrentAuthenticationPlugin(
);
// 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') {
Expand All @@ -1907,7 +1907,7 @@ public function getCurrentAuthenticationPlugin(
'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) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/SysInfo.php
Expand Up @@ -45,7 +45,7 @@ public static function getOs($php_os = PHP_OS)
/**
* Gets sysinfo class mathing current OS
*
* @return PhpMyAdmin\SysInfoBase|mixed sysinfo class
* @return SysInfoBase sysinfo class
*/
public static function get()
{
Expand All @@ -54,7 +54,7 @@ public static function get()

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;
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Table.php
Expand Up @@ -1005,7 +1005,7 @@ public static function moveCopy(
/**
* 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",
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/ThemeManager.php
Expand Up @@ -119,11 +119,11 @@ public function __construct()
}

/**
* 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();
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Tracking.php
Expand Up @@ -1170,7 +1170,7 @@ public function getVersionStatus(array $version)
* 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
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Util.php
Expand Up @@ -1949,7 +1949,7 @@ public static function checkParameters($params, $request = false)
*
* @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
Expand Down
2 changes: 1 addition & 1 deletion server_binlog.php
Expand Up @@ -24,7 +24,7 @@
$container->set('PhpMyAdmin\Response', Response::getInstance());
$container->alias('response', 'PhpMyAdmin\Response');

/** @var ServerBinlogController $controller */
/** @var \PhpMyAdmin\Controllers\Server\ServerBinlogController $controller */
$controller = $container->get(
'ServerBinlogController',
[]
Expand Down
2 changes: 1 addition & 1 deletion setup/index.php
Expand Up @@ -19,7 +19,7 @@
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';
Expand Down
2 changes: 1 addition & 1 deletion setup/lib/ConfigGenerator.php
Expand Up @@ -154,7 +154,7 @@ private static function _exportZeroBasedArray(array $array, $crlf)
* @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)
{
Expand Down
2 changes: 1 addition & 1 deletion tbl_operations.php
Expand Up @@ -189,7 +189,7 @@
. 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();
Expand Down
4 changes: 1 addition & 3 deletions test/classes/Config/FormDisplayTest.php
Expand Up @@ -211,9 +211,7 @@ public function testFixErrors()
$attrIsValidated->setAccessible(true);
$attrIsValidated->setValue($this->object, []);

$this->assertNull(
$this->object->fixErrors()
);
$this->object->fixErrors();

$arr = [
"Servers/1/test" => ['e1'],
Expand Down

0 comments on commit cc26651

Please sign in to comment.