From 7ac1d21c7023ffdc7fe34b4a7f4a0c6a3cab67bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 5 Dec 2019 19:49:28 -0300 Subject: [PATCH] Fix some PHPStan level 2 errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Table/StructureController.php | 1 + .../classes/Navigation/NavigationTree.php | 3 +- libraries/mult_submits.inc.php | 2 ++ libraries/tbl_columns_definition_form.inc.php | 2 ++ phpstan.neon.dist | 29 ++++--------------- test/bootstrap-phpstan.php | 3 ++ test/classes/ConfigTest.php | 2 +- test/classes/EnvironmentTest.php | 6 +++- test/classes/PmaTestCase.php | 7 +++-- 9 files changed, 25 insertions(+), 30 deletions(-) diff --git a/libraries/classes/Controllers/Table/StructureController.php b/libraries/classes/Controllers/Table/StructureController.php index 3df3a98c64..1ac3b71ee9 100644 --- a/libraries/classes/Controllers/Table/StructureController.php +++ b/libraries/classes/Controllers/Table/StructureController.php @@ -349,6 +349,7 @@ class StructureController extends AbstractController $db = &$this->db; $table = &$this->table; $url_params = []; + $db_is_system_schema = false; include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; $this->_db_is_system_schema = $db_is_system_schema; $this->_url_query = Url::getCommonRaw([ diff --git a/libraries/classes/Navigation/NavigationTree.php b/libraries/classes/Navigation/NavigationTree.php index 8694e32330..ee7536e780 100644 --- a/libraries/classes/Navigation/NavigationTree.php +++ b/libraries/classes/Navigation/NavigationTree.php @@ -832,8 +832,7 @@ class NavigationTree $keySeparatorLength ) ); - - if ($newChild instanceof NodeDatabase + if ($child instanceof NodeDatabase && $child->getHiddenCount() > 0 ) { $newChild->setHiddenCount($child->getHiddenCount()); diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index b75fe06051..9638e93654 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -52,6 +52,8 @@ global $db, $table, $clause_is_unique, $from_prefix, $goto, $multSubmits = new MultSubmits(); $template = new Template(); +$action = $action ?? ''; + /** * Prepares the work and runs some other scripts if required */ diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 9c3da644f6..fba5bd43d1 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -68,6 +68,8 @@ $form_params = [ 'db' => $db, ]; +$action = $action ?? ''; + if ($action == Url::getFromRoute('/table/create')) { $form_params['reload'] = 1; } else { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6b4f641fd2..a3d5774b13 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,34 +6,17 @@ parameters: reportUnmatchedIgnoredErrors: true inferPrivatePropertyTypeFromConstructor: true ignoreErrors: - - '#NodeTrans::__construct\(\) does not call parent constructor#' - - '#PHPUnit\\Framework\\MockObject#' - - '#Call to an undefined method PhpMyAdmin\\Navigation\\Nodes\\Node\:\:getHiddenCount#' - - '#Variable \$http_response_header in isset\(\) always exists and is not nullable#' + - '#Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject#' + - '#Access to an undefined property PHPUnit\\Framework\\MockObject\\MockObject#' - - message: '#Undefined variable: \$action#' - path: %currentWorkingDirectory%/libraries/mult_submits.inc.php + message: '#PhpMyAdmin\\Twig\\I18n\\NodeTrans::__construct\(\) does not call parent constructor from Twig_Extensions_Node_Trans#' + path: %currentWorkingDirectory%/libraries/classes/Twig/I18n/NodeTrans.php - - message: '#Undefined variable: \$action#' - path: %currentWorkingDirectory%/libraries/tbl_columns_definition_form.inc.php - - - message: '#Undefined variable: \$cfg#' - path: %currentWorkingDirectory%/test/classes/ConfigTest.php - - - message: '#Undefined variable: \$cfg#' - path: %currentWorkingDirectory%/test/classes/PmaTestCase.php - - - message: '#Undefined variable: \$cfg#' - path: %currentWorkingDirectory%/test/bootstrap-phpstan.php - - - message: '#Undefined variable: \$db_is_system_schema#' - path: %currentWorkingDirectory%/libraries/classes/Controllers/Table/StructureController.php + message: '#Variable \$http_response_header in isset\(\) always exists and is not nullable#' + path: %currentWorkingDirectory%/libraries/classes/Utils/HttpRequest.php - message: '#Instantiated class Sami\\Sami not found#' path: %currentWorkingDirectory%/test/sami-config.php - - - message: '#Variable \$pdo might not be defined#' - path: %currentWorkingDirectory%/test/classes/EnvironmentTest.php - message: '#Function uploadprogress_get_info not found#' path: %currentWorkingDirectory%/libraries/classes/Plugins/Import/Upload/UploadProgress.php diff --git a/test/bootstrap-phpstan.php b/test/bootstrap-phpstan.php index 667b2ca5f7..006e409c36 100644 --- a/test/bootstrap-phpstan.php +++ b/test/bootstrap-phpstan.php @@ -18,10 +18,13 @@ if (! defined('ROOT_PATH')) { define('PHPMYADMIN', true); define('TESTSUITE', true); +$cfg = []; + include_once ROOT_PATH . 'examples/signon-script.php'; require_once ROOT_PATH . 'libraries/config.default.php'; require_once ROOT_PATH . 'libraries/vendor_config.php'; require_once AUTOLOAD_FILE; + $GLOBALS['cfg'] = $cfg; $GLOBALS['server'] = 0; $GLOBALS['PMA_Config'] = new Config(); diff --git a/test/classes/ConfigTest.php b/test/classes/ConfigTest.php index eacfc40637..fa7e8b496d 100644 --- a/test/classes/ConfigTest.php +++ b/test/classes/ConfigTest.php @@ -394,8 +394,8 @@ class ConfigTest extends PmaTestCase $this->object->default_source = $prevDefaultSource; + $cfg = []; include $this->object->default_source; - $loadedConf = $cfg; unset($cfg); diff --git a/test/classes/EnvironmentTest.php b/test/classes/EnvironmentTest.php index 6e9a30c960..1435dcdc27 100644 --- a/test/classes/EnvironmentTest.php +++ b/test/classes/EnvironmentTest.php @@ -61,9 +61,13 @@ class EnvironmentTest extends TestCase } // Check id MySQL server is 5 version + $serverVersion = '0.0.0'; + if (isset($pdo)) { + $serverVersion = $pdo->getAttribute(constant('PDO::ATTR_SERVER_VERSION')); + } preg_match( '/^(\d+)?\.(\d+)?\.(\*|\d+)/', - $pdo->getAttribute(constant('PDO::ATTR_SERVER_VERSION')), + $serverVersion, $version_parts ); $this->assertEquals(5, $version_parts[1]); diff --git a/test/classes/PmaTestCase.php b/test/classes/PmaTestCase.php index 0c051927dd..9ddcaf8f06 100644 --- a/test/classes/PmaTestCase.php +++ b/test/classes/PmaTestCase.php @@ -9,7 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests; use PhpMyAdmin\Response; -use PHPUnit\Framework\MockObject\MockBuilder; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -37,6 +37,7 @@ class PmaTestCase extends TestCase */ public static function setUpBeforeClass(): void { + $cfg = []; require ROOT_PATH . 'libraries/config.default.php'; $GLOBALS['cfg'] = $cfg; } @@ -46,13 +47,13 @@ class PmaTestCase extends TestCase * * @param mixed[] ...$param parameter for header method * - * @return MockBuilder + * @return MockObject */ public function mockResponse(...$param) { $this->restoreInstance = Response::getInstance(); - $mockResponse = $this->getMockBuilder('PhpMyAdmin\Response') + $mockResponse = $this->getMockBuilder(Response::class) ->disableOriginalConstructor() ->setMethods([ 'header',