diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php
index a3ab486f8f0..8677dad5fac 100644
--- a/src/Psalm/Config.php
+++ b/src/Psalm/Config.php
@@ -103,6 +103,7 @@
class Config
{
private const DEFAULT_FILE_NAME = 'psalm.xml';
+ public const CONFIG_NAMESPACE = 'https://getpsalm.org/schema/config';
public const REPORT_INFO = 'info';
public const REPORT_ERROR = 'error';
public const REPORT_SUPPRESS = 'suppress';
@@ -708,7 +709,7 @@ private static function validateXmlConfig(string $base_dir, string $file_content
}
if (!$psalm_node->hasAttribute('xmlns')) {
- $psalm_node->setAttribute('xmlns', 'https://getpsalm.org/schema/config');
+ $psalm_node->setAttribute('xmlns', self::CONFIG_NAMESPACE);
$old_dom_document = $dom_document;
$dom_document = self::loadDomDocument($base_dir, $old_dom_document->saveXML());
@@ -766,21 +767,27 @@ private static function processConfigDeprecations(
string $file_contents,
string $config_path
): void {
+ $config->config_issues = [];
+
// Attributes to be removed in Psalm 5
$deprecated_attributes = [
'allowCoercionFromStringToClassConst',
'allowPhpStormGenerics',
- 'exitFunctions'
];
- $config->config_issues = [];
+ $deprecated_elements = [
+ 'exitFunctions',
+ ];
+
$psalm_element_item = $dom_document->getElementsByTagName('psalm')->item(0);
assert($psalm_element_item !== null);
$attributes = $psalm_element_item->attributes;
+
foreach ($attributes as $attribute) {
if (in_array($attribute->name, $deprecated_attributes, true)) {
$line = $attribute->getLineNo();
assert($line > 0); // getLineNo() always returns non-zero for nodes loaded from file
+
$offset = self::lineNumberToByteOffset($file_contents, $line);
$attribute_start = strrpos($file_contents, $attribute->name, $offset - strlen($file_contents)) ?: 0;
$attribute_end = $attribute_start + strlen($attribute->name) - 1;
@@ -798,6 +805,35 @@ private static function processConfigDeprecations(
);
}
}
+
+ foreach ($deprecated_elements as $deprecated_element) {
+ $deprecated_elements_xml = $dom_document->getElementsByTagNameNS(
+ self::CONFIG_NAMESPACE,
+ $deprecated_element
+ );
+ if ($deprecated_elements_xml->count()) {
+ $deprecated_element_xml = $deprecated_elements_xml->item(0);
+ assert($deprecated_element_xml !== null);
+ $line = $deprecated_element_xml->getLineNo();
+ assert($line > 0);
+
+ $offset = self::lineNumberToByteOffset($file_contents, $line);
+ $element_start = strpos($file_contents, $deprecated_element, $offset) ?: 0;
+ $element_end = $element_start + strlen($deprecated_element) - 1;
+
+ $config->config_issues[] = new ConfigIssue(
+ 'Element "' . $deprecated_element . '" is deprecated '
+ . 'and is going to be removed in the next major version',
+ new CodeLocation\Raw(
+ $file_contents,
+ $config_path,
+ basename($config_path),
+ $element_start,
+ $element_end
+ )
+ );
+ }
+ }
}
/**
diff --git a/src/Psalm/Internal/PluginManager/ConfigFile.php b/src/Psalm/Internal/PluginManager/ConfigFile.php
index 482a8c59d11..1dc87b9d098 100644
--- a/src/Psalm/Internal/PluginManager/ConfigFile.php
+++ b/src/Psalm/Internal/PluginManager/ConfigFile.php
@@ -12,7 +12,6 @@
class ConfigFile
{
- public const NS = 'https://getpsalm.org/schema/config';
/** @var string */
private $path;
@@ -94,7 +93,7 @@ public function addPlugin(string $plugin_class): void
$plugin_class_element = $config_xml->createElement('pluginClass');
if ($plugin_class_element) {
- $plugin_class_element->setAttribute('xmlns', self::NS);
+ $plugin_class_element->setAttribute('xmlns', Config::CONFIG_NAMESPACE);
$plugin_class_element->setAttribute('class', $plugin_class);
if ($plugins_element) {
$plugins_element->appendChild($plugin_class_element);
diff --git a/tests/Config/ConfigFileTest.php b/tests/Config/ConfigFileTest.php
index 9b16d99c799..2b7152260c8 100644
--- a/tests/Config/ConfigFileTest.php
+++ b/tests/Config/ConfigFileTest.php
@@ -69,7 +69,7 @@ public function addCanAddPluginClassToExistingPluginsNode(): void
-
+
',
file_get_contents($this->file_path)
));
@@ -91,7 +91,7 @@ public function addCanCreateMissingPluginsNode(): void
$this->assertTrue(static::compareContentWithTemplateAndTrailingLineEnding(
'
- ',
+ ',
file_get_contents($this->file_path)
));
}