Skip to content

Commit

Permalink
PHPStan: some fixes to lib/ files (#3099)
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano authored Mar 28, 2023
1 parent 28db818 commit 62d17a8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 89 deletions.
6 changes: 4 additions & 2 deletions lib/Varien/Data/Tree/Dbp.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public function __construct($connection, $table, $fields)
$this->_orderField = $fields[self::ORDER_FIELD];
$this->_levelField = $fields[self::LEVEL_FIELD];

$this->_select = $this->_conn->select();
/** @var Varien_Db_Select $select */
$select = $this->_conn->select();
$this->_select = $select;
$this->_select->from($this->_table);
}

Expand Down Expand Up @@ -158,7 +160,7 @@ public function load($parentNode = null, $recursionLevel = 0)
$parentNode = null;
} elseif (is_string($parentNode)) {
$parentPath = $parentNode;
$startLevel = count(explode($parentPath)) - 1;
$startLevel = count(explode('/', $parentPath)) - 1;
$parentNode = null;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Varien/Db/Adapter/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,7 @@ public function getCaseSql($valueName, $casesResults, $defaultValue = null);
* @param string $value OPTIONAL. Applies when $expression is NULL
* @return Zend_Db_Expr
*/

public function getIfNullSql($expression, $value = 0);
public function getIfNullSql($expression, $value = '0');

/**
* Generate fragment of SQL, that combine together (concatenate) the results from data array
Expand Down
28 changes: 17 additions & 11 deletions lib/Varien/Db/Adapter/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function _connect()
// Suppress connection warnings here.
// Throw an exception instead.
@$conn = new mysqli();
if (false === $conn || mysqli_connect_errno()) {
if (mysqli_connect_errno()) {
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_errno());
}

Expand All @@ -61,15 +61,15 @@ protected function _connect()
list($this->_config['host'], $port) = explode(':', $this->_config['host']);
}

@$conn->real_connect(
$connectionSuccessful = @$conn->real_connect(
$this->_config['host'],
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname'],
$port,
$socket
);
if (mysqli_connect_errno()) {
if (!$connectionSuccessful) {
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error());
}

Expand All @@ -83,7 +83,7 @@ protected function _connect()
* Run RAW Query
*
* @param string $sql
* @return Zend_Db_Statement_Interface
* @return mysqli_result
*/
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function raw_query($sql)
Expand All @@ -94,7 +94,9 @@ public function raw_query($sql)
$retry = false;
try {
$this->clear_result();
$result = $this->getConnection()->query($sql);
/** @var mysqli $connection */
$connection = $this->getConnection();
$result = $connection->query($sql);
$this->clear_result();
} catch (Exception $e) {
if ($tries < 10 && $e->getMessage() == $timeoutMessage) {
Expand Down Expand Up @@ -147,11 +149,13 @@ public function multi_query($sql)
$this->beginTransaction();
try {
$this->clear_result();
if ($this->getConnection()->multi_query($sql)) {
/** @var mysqli $connection */
$connection = $this->getConnection();
if ($connection->multi_query($sql)) {
$this->clear_result();
$this->commit();
} else {
throw new Zend_Db_Adapter_Mysqli_Exception('multi_query: ' . $this->getConnection()->error);
throw new Zend_Db_Adapter_Mysqli_Exception('multi_query: ' . $connection->error);
}
} catch (Exception $e) {
$this->rollBack();
Expand All @@ -164,11 +168,13 @@ public function multi_query($sql)
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function clear_result()
{
while ($this->getConnection()->next_result()) {
if ($result = $this->getConnection()->store_result()) {
/** @var mysqli $connection */
$connection = $this->getConnection();
while ($connection->next_result()) {
if ($result = $connection->store_result()) {
$result->free_result();
} elseif ($this->getConnection()->error) {
throw new Zend_Db_Adapter_Mysqli_Exception('clear_result: ' . $this->getConnection()->error);
} elseif ($connection->error) {
throw new Zend_Db_Adapter_Mysqli_Exception('clear_result: ' . $connection->error);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,7 @@ public function getCheckSql($expression, $true, $false)
* @param string|int $value OPTIONAL. Applies when $expression is NULL
* @return Zend_Db_Expr
*/
public function getIfNullSql($expression, $value = 0)
public function getIfNullSql($expression, $value = '0')
{
if ($expression instanceof Zend_Db_Expr || $expression instanceof Zend_Db_Select) {
$expression = sprintf("IFNULL((%s), %s)", $expression, $value);
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected static function _formatCalledArgument($arg)
}
} elseif (is_null($arg)) {
$out .= 'NULL';
} elseif (is_numeric($arg) || is_float($arg)) {
} elseif (is_numeric($arg)) {
$out .= $arg;
} elseif (is_string($arg)) {
if (strlen($arg) > self::$argLength) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Image/Adapter/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function quality($value = null)
* Get/set keepBackgroundColor
*
* @param array $value
* @return array
* @return array|void
*/
public function backgroundColor($value = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Image/Adapter/Gd2.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct()
*/
public function destruct()
{
if (is_resource($this->_imageHandler) || $this->_imageHandler instanceof \GdImage) {
if (is_resource($this->_imageHandler) || (class_exists('GdImage') && $this->_imageHandler instanceof \GdImage)) {
@imagedestroy($this->_imageHandler);
}
}
Expand Down
70 changes: 0 additions & 70 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4925,66 +4925,11 @@ parameters:
count: 1
path: lib/Varien/Data/Form/Element/Multiline.php

-
message: "#^Function explode invoked with 1 parameter, 2\\-3 required\\.$#"
count: 1
path: lib/Varien/Data/Tree/Dbp.php

-
message: "#^Property Varien_Data_Tree_Dbp\\:\\:\\$_select \\(Varien_Db_Select\\) does not accept Zend_Db_Select\\.$#"
count: 1
path: lib/Varien/Data/Tree/Dbp.php

-
message: "#^Method Varien_Data_Tree\\:\\:load\\(\\) invoked with 2 parameters, 0\\-1 required\\.$#"
count: 1
path: lib/Varien/Data/Tree/Node.php

-
message: "#^Default value of the parameter \\#2 \\$value \\(int\\) of method Varien_Db_Adapter_Interface\\:\\:getIfNullSql\\(\\) is incompatible with type string\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Interface.php

-
message: "#^Call to an undefined method Zend_Db_Statement_Interface\\:\\:fetch_assoc\\(\\)\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Cannot access property \\$error on object\\|resource\\.$#"
count: 3
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Cannot call method multi_query\\(\\) on object\\|resource\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Cannot call method next_result\\(\\) on object\\|resource\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Cannot call method query\\(\\) on object\\|resource\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Cannot call method store_result\\(\\) on object\\|resource\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^If condition is always false\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Strict comparison using \\=\\=\\= between false and mysqli will always evaluate to false\\.$#"
count: 1
path: lib/Varien/Db/Adapter/Mysqli.php

-
message: "#^Cannot access offset 'Engine' on bool\\.$#"
count: 1
Expand Down Expand Up @@ -5060,11 +5005,6 @@ parameters:
count: 1
path: lib/Varien/Db/Tree/NodeSet.php

-
message: "#^Call to function is_float\\(\\) with mixed will always evaluate to false\\.$#"
count: 1
path: lib/Varien/Debug.php

-
message: "#^Call to an undefined method Varien_File_Uploader_Image\\:\\:newUploader\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -5095,21 +5035,11 @@ parameters:
count: 1
path: lib/Varien/Http/Adapter/Curl.php

-
message: "#^Method Varien_Image_Adapter_Abstract\\:\\:backgroundColor\\(\\) should return array but empty return statement found\\.$#"
count: 2
path: lib/Varien/Image/Adapter/Abstract.php

-
message: "#^Property Varien_Image_Adapter_Abstract\\:\\:\\$_imageHandler has unknown class GdImage as its type\\.$#"
count: 1
path: lib/Varien/Image/Adapter/Abstract.php

-
message: "#^Class GdImage not found\\.$#"
count: 1
path: lib/Varien/Image/Adapter/Gd2.php

-
message: "#^Call to an undefined method SimpleXMLElement\\:\\:setNode\\(\\)\\.$#"
count: 1
Expand Down

0 comments on commit 62d17a8

Please sign in to comment.