Skip to content

Commit

Permalink
phpstan level 0 (#14405)
Browse files Browse the repository at this point in the history
* Fix phpdoc @return

- Fixed @return typehint

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix incorrect case on function calls

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Type hint + typo fix

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fixes

- @return fix
- @var fix
- Class names
- Throws fix
- test/classes/Plugins/Export/ExportSqlTest.php any() invoked with 1 parameter, 0 required
-  libraries/classes/Controllers/Table/TableStructureController.php Array has 2 duplicate keys with value 'columns_list'
- Call parent constructor  libraries/classes/Error.php

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Update config

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Access to an undefined property

- Access to an undefined property PhpMyAdmin\Plugins\Schema\Pdf\PdfRelationSchema::$diagram_row
- Access to an undefined property PhpMyAdmin\Plugins\Schema\Pdf\Pdf::$cMargin
- Undefined properties

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Update config

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix bootstrap-phpstan

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix typos and phpstan config

Fixes: #14399
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes authored and MauricioFauth committed Jun 25, 2018
1 parent 4d83104 commit e816e45
Show file tree
Hide file tree
Showing 57 changed files with 213 additions and 121 deletions.
8 changes: 4 additions & 4 deletions libraries/classes/Config/Validator.php
Expand Up @@ -211,18 +211,18 @@ public static function testDBConnection(
}

if ($extension == 'mysql') {
$conn = @mysql_connect($host . $port . $socket, $user, $pass);
$conn = @\mysql_connect($host . $port . $socket, $user, $pass);
if (! $conn) {
$error = __('Could not connect to the database server!');
} else {
mysql_close($conn);
\mysql_close($conn);
}
} else {
$conn = @mysqli_connect($host, $user, $pass, null, $port, $socket);
$conn = @\mysqli_connect($host, $user, $pass, null, $port, $socket);
if (! $conn) {
$error = __('Could not connect to the database server!');
} else {
mysqli_close($conn);
\mysqli_close($conn);
}
}
if (! is_null($error)) {
Expand Down
Expand Up @@ -287,7 +287,7 @@ private function _getHtmlForDatabases(array $replication_types)
foreach ($column_order as $stat_name => $stat) {
if (array_key_exists($stat_name, $first_database)) {
if ($stat['format'] == 'byte') {
$byte_format = Util_formatByteDown($stat['footer'], 3, 1);
$byte_format = Util::formatByteDown($stat['footer'], 3, 1);
$values[$stat_name] = $byte_format[0];
$units[$stat_name] = $byte_format[1];
} elseif ($stat['format'] == 'number') {
Expand Down Expand Up @@ -486,7 +486,7 @@ public function _buildHtmlForDb(
$values[$stat_name] = $byte_format[0];
$units[$stat_name] = $byte_format[1];
} elseif ($stat['format'] == 'number') {
$values[$stat_name] = Util_formatNumber($stat['footer'], 0);
$values[$stat_name] = Util::formatNumber($stat['footer'], 0);
} else {
$values[$stat_name] = htmlentities($stat['footer'], 0);
}
Expand Down
12 changes: 6 additions & 6 deletions libraries/classes/Database/Qbe.php
Expand Up @@ -212,7 +212,7 @@ class Qbe
* Current search
*
* @access private
* @var SavedSearches
* @var \PhpMyAdmin\SavedSearches
*/
private $_currentSearch = null;

Expand All @@ -234,10 +234,10 @@ class Qbe
/**
* Public Constructor
*
* @param DatabaseInterface $dbi DatabaseInterface object
* @param string $dbname Database name
* @param array $savedSearchList List of saved searches
* @param SavedSearches $currentSearch Current search id
* @param DatabaseInterface $dbi DatabaseInterface object
* @param string $dbname Database name
* @param array $savedSearchList List of saved searches
* @param \PhpMyAdmin\SavedSearches $currentSearch Current search id
*/
public function __construct(
$dbi,
Expand Down Expand Up @@ -280,7 +280,7 @@ private function _loadCriterias()
/**
* Getter for current search
*
* @return SavedSearches
* @return \PhpMyAdmin\SavedSearches
*/
private function _getCurrentSearch()
{
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/DatabaseInterface.php
Expand Up @@ -362,10 +362,10 @@ public function tryQuery(
/**
* Run multi query statement and return results
*
* @param string $multi_query multi query statement to execute
* @param mysqli $link mysqli object
* @param string $multi_query multi query statement to execute
* @param \mysqli $link mysqli object
*
* @return mysqli_result collection | boolean(false)
* @return \mysqli_result[] | boolean(false)
*/
public function tryMultiQuery(
string $multi_query = '',
Expand Down
9 changes: 5 additions & 4 deletions libraries/classes/Error.php
Expand Up @@ -101,6 +101,7 @@ class Error extends Message
*/
public function __construct(int $errno, string $errstr, string $errfile, int $errline)
{
parent::__construct();
$this->setNumber($errno);
$this->setMessage($errstr, false);
$this->setFile($errfile);
Expand Down Expand Up @@ -420,16 +421,16 @@ public static function getArg($arg, string $function): string
if (in_array($function, $include_functions)) {
$retval .= self::relPath($arg);
} elseif (in_array($function, $connect_functions)
&& getType($arg) === 'string'
&& gettype($arg) === 'string'
) {
$retval .= getType($arg) . ' ********';
$retval .= gettype($arg) . ' ********';
} elseif (is_scalar($arg)) {
$retval .= getType($arg) . ' '
$retval .= gettype($arg) . ' '
. htmlspecialchars(var_export($arg, true));
} elseif (is_object($arg)) {
$retval .= '<Class:' . get_class($arg) . '>';
} else {
$retval .= getType($arg);
$retval .= gettype($arg);
}

return $retval;
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Footer.php
Expand Up @@ -138,7 +138,7 @@ public function getDebugMessage(): string
// Remove recursions and iterators from $_SESSION['debug']
self::_removeRecursion($_SESSION['debug']);

$retval = JSON_encode($_SESSION['debug']);
$retval = json_encode($_SESSION['debug']);
$_SESSION['debug'] = [];
return json_last_error() ? '\'false\'' : $retval;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Gis/GisVisualization.php
Expand Up @@ -511,7 +511,7 @@ public function toFileAsPdf($file_name)
public function toImage($format)
{
if ($format == 'svg') {
return $this->asSvg();
return $this->asSVG();
} elseif ($format == 'png') {
return $this->asPng();
} elseif ($format == 'ol') {
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Logging.php
Expand Up @@ -48,7 +48,7 @@ public static function getLogDestination()
* @param string $user user name
* @param string $status status message
*
* @return void
* @return string
*/
public static function getLogMessage($user, $status)
{
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/Plugins.php
Expand Up @@ -367,15 +367,15 @@ public static function getOneOption(
$doc = $propertyGroup->getDoc();
if ($doc != null) {
if (count($doc) == 3) {
$ret .= PhpMyAdmin\Util::showMySQLDocu(
$ret .= \PhpMyAdmin\Util::showMySQLDocu(
$doc[1],
false,
$doc[2]
);
} elseif (count($doc) == 1) {
$ret .= PhpMyAdmin\Util::showDocu('faq', $doc[0]);
$ret .= \PhpMyAdmin\Util::showDocu('faq', $doc[0]);
} else {
$ret .= PhpMyAdmin\Util::showMySQLDocu(
$ret .= \PhpMyAdmin\Util::showMySQLDocu(
$doc[1]
);
}
Expand Down
38 changes: 29 additions & 9 deletions libraries/classes/Plugins/Export/Helpers/Pdf.php
Expand Up @@ -28,6 +28,26 @@ class Pdf extends PdfLib
public $tablewidths;
public $headerset;

private $dataY;
private $cellFontSize;
private $titleFontSize;
private $titleText;
private $dbAlias;
private $tableAlias;
private $purpose;
private $colTitles;
private $results;
private $colAlign;
private $titleWidth;
private $colFits;
private $display_column;
private $numFields;
private $fields;
private $sColWidth;
private $currentDb;
private $currentTable;
private $aliases;

/**
* @var Relation $relation
*/
Expand Down Expand Up @@ -179,14 +199,14 @@ public function Header()
$txt
);
$l += $this->tablewidths[$col];
$maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY;
$maxY = ($maxY < $this->GetY()) ? $this->GetY() : $maxY;
}
$this->SetXY($this->lMargin, $this->tMargin);
$this->setFillColor(200, 200, 200);
$this->SetFillColor(200, 200, 200);
$l = ($this->lMargin);
foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l, $this->tMargin);
$this->cell(
$this->Cell(
$this->tablewidths[$col],
$maxY - ($this->tMargin),
'',
Expand All @@ -205,7 +225,7 @@ public function Header()
);
$l += $this->tablewidths[$col];
}
$this->setFillColor(255, 255, 255);
$this->SetFillColor(255, 255, 255);
// set headerset
$this->headerset[$this->page] = 1;
}
Expand Down Expand Up @@ -373,7 +393,7 @@ public function getTriggers($db, $table)

// Starting to fill table with required info

$this->setY($this->tMargin);
$this->SetY($this->tMargin);
$this->AddPage();
$this->SetFont(PdfLib::PMA_PDF_FONT, '', 9);

Expand Down Expand Up @@ -555,7 +575,7 @@ public function getTableDef(

// Starting to fill table with required info

$this->setY($this->tMargin);
$this->SetY($this->tMargin);
$this->AddPage();
$this->SetFont(PdfLib::PMA_PDF_FONT, '', 9);

Expand Down Expand Up @@ -742,7 +762,7 @@ public function mysqlReport($query)
if (!empty($this->aliases[$db]['tables'][$table]['columns'][$col_as])) {
$col_as = $this->aliases[$db]['tables'][$table]['columns'][$col_as];
}
$stringWidth = $this->getstringwidth($col_as) + 6;
$stringWidth = $this->GetStringWidth($col_as) + 6;
// save the real title's width
$titleWidth[$i] = $stringWidth;
$totalTitleWidth += $stringWidth;
Expand Down Expand Up @@ -797,7 +817,7 @@ public function mysqlReport($query)
*/
while ($row = $GLOBALS['dbi']->fetchRow($this->results)) {
foreach ($colFits as $key => $val) {
$stringWidth = $this->getstringwidth($row[$key]) + 6;
$stringWidth = $this->GetStringWidth($row[$key]) + 6;
if ($adjustingMode && ($stringWidth > $this->sColWidth)) {
// any column whose data's width is bigger than
// the start width is now discarded
Expand Down Expand Up @@ -850,7 +870,7 @@ public function mysqlReport($query)
DatabaseInterface::CONNECT_USER,
DatabaseInterface::QUERY_UNBUFFERED
);
$this->setY($this->tMargin);
$this->SetY($this->tMargin);
$this->AddPage();
$this->SetFont(PdfLib::PMA_PDF_FONT, '', 9);
$this->morepagestable($this->FontSizePt);
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Plugins/Import/ImportSql.php
Expand Up @@ -174,8 +174,8 @@ public function doImport(array &$sql_data = [])
/**
* Handle compatibility options
*
* @param PhpMyAdmin\DatabaseInterface $dbi Database interface
* @param array $request Request array
* @param \PhpMyAdmin\DatabaseInterface $dbi Database interface
* @param array $request Request array
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Plugins/Schema/Dia/DiaRelationSchema.php
Expand Up @@ -76,7 +76,7 @@ public function __construct($db)
$alltables = $this->getTablesFromRequest();

foreach ($alltables as $table) {
if (!isset($this->tables[$table])) {
if (!isset($this->_tables[$table])) {
$this->_tables[$table] = new TableStatsDia(
$this->diagram,
$this->db,
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Plugins/Schema/Pdf/Pdf.php
Expand Up @@ -50,6 +50,7 @@ class Pdf extends PdfLib
public $Outlines = [];
public $def_outlines;
public $widths;
public $cMargin;
private $_ff = PdfLib::PMA_PDF_FONT;
private $_offline;
private $_pageNumber;
Expand Down Expand Up @@ -325,7 +326,7 @@ public function row(array $data, array $links)
$il = $this->FontSize;
$h = ($il + 1) * $nb;
// page break if necessary
$this->CheckPageBreak($h);
$this->checkPageBreak($h);
// draw the cells
$data_cnt = count($data);
for ($i = 0; $i < $data_cnt; $i++) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php
Expand Up @@ -754,7 +754,7 @@ public function dataDictionaryDoc(array $alltables)
}
}

$this->diagram_row = [
$diagram_row = [
$field_name,
$type,
$attribute,
Expand All @@ -781,7 +781,7 @@ public function dataDictionaryDoc(array $alltables)
} else {
unset($links[6]);
}
$this->diagram->row($this->diagram_row, $links);
$this->diagram->row($diagram_row, $links);
} // end foreach
$this->diagram->SetFont($this->_ff, '', 14);
} //end each
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Rte/Routines.php
Expand Up @@ -1734,7 +1734,7 @@ public function getExecuteForm(array $routine)
$input_type = 'checkbox';
}
foreach ($routine['item_param_length_arr'][$i] as $value) {
$value = htmlentities(Util::unquote($value), ENT_QUOTES);
$value = htmlentities(Util::unQuote($value), ENT_QUOTES);
$retval .= "<input name='params["
. $routine['item_param_name'][$i] . "][]' "
. "value='" . $value . "' type='"
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Server/Privileges.php
Expand Up @@ -966,7 +966,7 @@ public function getHtmlForRoutineSpecificPrivileges(
/**
* Get routine privilege table as an array
*
* @return privilege type array
* @return array privilege type array
*/
public function getTriggerPrivilegeTable()
{
Expand Down
8 changes: 4 additions & 4 deletions libraries/classes/Table.php
Expand Up @@ -400,7 +400,7 @@ public function getNumRows()
{
$table_num_row_info = $this->getStatusInfo('TABLE_ROWS', false, true);
if (false === $table_num_row_info) {
$table_num_row_info = $this->_dbi->getTable($this->_db_name, $showtable['Name'])
$table_num_row_info = $this->_dbi->getTable($this->_db_name, $GLOBALS['showtable']['Name'])
->countRecords(true);
}
return $table_num_row_info ? $table_num_row_info : 0 ;
Expand Down Expand Up @@ -2003,7 +2003,7 @@ public function setUiProp($property, $value, $table_create_time = null)
// check if pmadb is set
$cfgRelation = $this->relation->getRelationsParam();
if ($cfgRelation['uiprefswork']) {
return $this->saveUiprefsToDb();
return $this->saveUiPrefsToDb();
}
return true;
}
Expand All @@ -2026,7 +2026,7 @@ public function removeUiProp($property)
// check if pmadb is set
$cfgRelation = $this->relation->getRelationsParam();
if ($cfgRelation['uiprefswork']) {
return $this->saveUiprefsToDb();
return $this->saveUiPrefsToDb();
}
}
return true;
Expand Down Expand Up @@ -2167,7 +2167,7 @@ public function getSqlQueryForIndexCreateOrEdit($index, &$error)
$keyBlockSizes = $index->getKeyBlockSize();
if (! empty($keyBlockSizes)) {
$sql_query .= sprintf(
' KEY_BLOCK_SIZE = ',
' KEY_BLOCK_SIZE = %s',
$GLOBALS['dbi']->escapeString($keyBlockSizes)
);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Twig/I18n/TokenParserTrans.php
Expand Up @@ -24,7 +24,7 @@ class TokenParserTrans extends TransTokenParser
*
* @param Token $token Twig token to parse
*
* @return Twig_NodeInterface
* @return \Twig\Extensions\Node\TransNode
*
* @throws \Twig\Error\SyntaxError
*/
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/TwoFactor.php
Expand Up @@ -177,7 +177,7 @@ public function getBackendClass($name)
/**
* Returns backend for current user
*
* @return PhpMyAdmin\Plugins\TwoFactorPlugin
* @return \PhpMyAdmin\Plugins\TwoFactorPlugin
*/
public function getBackend()
{
Expand Down Expand Up @@ -226,7 +226,7 @@ public function setup()
/**
* Saves current configuration.
*
* @return true|PhpMyAdmin\Message
* @return true|\PhpMyAdmin\Message
*/
public function save()
{
Expand Down

0 comments on commit e816e45

Please sign in to comment.