From 28a3efef4db501c041c55890686eb49294e2f074 Mon Sep 17 00:00:00 2001 From: AndrolGenhald Date: Thu, 9 Dec 2021 17:13:52 -0600 Subject: [PATCH] Fix copy/paste fail and other psalm/cs issues, reduce duplication of literals. --- src/Psalm/Config.php | 27 +++++---------------------- tests/Config/ConfigFileTest.php | 2 +- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 20e14a45a72..73f209fe5c2 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -41,6 +41,7 @@ use XdgBaseDir\Xdg; use stdClass; +use function array_key_exists; use function array_map; use function array_merge; use function array_pad; @@ -971,33 +972,19 @@ private static function fromXmlAndPaths( throw new UnexpectedValueException('Invalid composer.json at ' . $composer_json_path); } } - foreach ([ - "decimal", - "dom", - "ds", - "geos", - "mongodb", - "mysqli", - "pdo", - "soap", - "xdebug", - ] as $ext) { + foreach ($config->php_extensions as $ext => $_) { $config->php_extensions[$ext] = isset($composer_json["require"]["ext-$ext"]); } if ($config->load_xdebug_stub !== null) { - $config->php_extensions[$ext] = $config->load_xdebug_stub; + $config->php_extensions["xdebug"] = $config->load_xdebug_stub; } if (isset($config_xml->enableExtensions) && isset($config_xml->enableExtensions->extension)) { foreach ($config_xml->enableExtensions->extension as $extension) { assert(isset($extension["name"])); $extensionName = (string) $extension["name"]; - assert(in_array( - $extensionName, - ["decimal", "dom", "ds", "geos", "mongodb", "mysqli", "pdo", "soap", "xdebug"], - true - )); + assert(array_key_exists($extensionName, $config->php_extensions)); $config->php_extensions[$extensionName] = true; } } @@ -1006,11 +993,7 @@ private static function fromXmlAndPaths( foreach ($config_xml->disableExtensions->extension as $extension) { assert(isset($extension["name"])); $extensionName = (string) $extension["name"]; - assert(in_array( - $extensionName, - ["decimal", "dom", "ds", "geos", "mongodb", "mysqli", "pdo", "soap", "xdebug"], - true - )); + assert(array_key_exists($extensionName, $config->php_extensions)); $config->php_extensions[$extensionName] = false; } } diff --git a/tests/Config/ConfigFileTest.php b/tests/Config/ConfigFileTest.php index fb49ccab602..2b1d2efcb90 100644 --- a/tests/Config/ConfigFileTest.php +++ b/tests/Config/ConfigFileTest.php @@ -2,6 +2,7 @@ namespace Psalm\Tests\Config; use Psalm\Config; +use Psalm\Exception\ConfigException; use Psalm\Internal\PluginManager\ConfigFile; use Psalm\Internal\RuntimeCaches; use Psalm\Tests\TestCase; @@ -15,7 +16,6 @@ use function unlink; use const PHP_EOL; -use Psalm\Exception\ConfigException; /** @group PluginManager */ class ConfigFileTest extends TestCase