From da69e60cf305c8efe19c9a6c3aa3b33331fbfeb4 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sat, 21 Apr 2018 19:05:26 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20error=20on=20existing=20Psalm?= =?UTF-8?q?=20configs=20cc=20@ostrolucky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xsd | 8 ++++---- psalm.xml.dist | 3 ++- src/Psalm/Config.php | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/config.xsd b/config.xsd index 1b8519c31..6e6d82868 100644 --- a/config.xsd +++ b/config.xsd @@ -1,9 +1,9 @@ diff --git a/psalm.xml.dist b/psalm.xml.dist index a29f052ca..0cf1ba819 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -7,7 +7,8 @@ rememberPropertyAssignmentsAfterCall="true" throwExceptionOnError="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="config.xsd" + xmlns="https://getpsalm.org/schema/config" + xsi:schemaLocation="https://getpsalm.org/schema/config config.xsd" > diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index abe991e64..6a64aa497 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -362,6 +362,25 @@ class Config $dom_document = new \DOMDocument(); $dom_document->loadXML($file_contents); + $psalm_nodes = $dom_document->getElementsByTagName('psalm'); + + /** @var \DomElement|null */ + $psalm_node = $psalm_nodes->item(0); + + if (!$psalm_node) { + throw new ConfigException( + 'Missing psalm node' + ); + } + + if (!$psalm_node->hasAttribute('xmlns')) { + $psalm_node->setAttribute('xmlns', 'https://getpsalm.org/schema/config'); + + $old_dom_document = $dom_document; + $dom_document = new \DOMDocument(); + $dom_document->loadXML($old_dom_document->saveXml()); + } + // Enable user error handling libxml_use_internal_errors(true);