From 55eb4b018bdf1858cc442675ec849c96226c38dd Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Mon, 3 Jan 2022 12:41:17 +0200 Subject: [PATCH] Dropped removed config entries --- config.xsd | 10 ----- src/Psalm/Config.php | 104 ++++++++++++++++++++++++------------------- 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/config.xsd b/config.xsd index 95d079cf76c..46840b0a3a9 100644 --- a/config.xsd +++ b/config.xsd @@ -32,16 +32,6 @@ - - - - - - Deprecated. Has no effect since Psalm 3 and is going to be removed in Psalm 5. - - - - diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index f7e35324f92..ad27a3e237a 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -5,6 +5,7 @@ use Composer\Autoload\ClassLoader; use Composer\Semver\Constraint\Constraint; use Composer\Semver\VersionParser; +use DOMAttr; use DOMDocument; use DomElement; use InvalidArgumentException; @@ -762,6 +763,58 @@ private static function lineNumberToByteOffset(string $string, int $line_number) return $offset; } + private static function processDeprecatedAttribute( + DOMAttr $attribute, + string $file_contents, + self $config, + string $config_path + ): void { + $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; + + $config->config_issues[] = new ConfigIssue( + 'Attribute "' . $attribute->name . '" is deprecated ' + . 'and is going to be removed in the next major version', + new Raw( + $file_contents, + $config_path, + basename($config_path), + $attribute_start, + $attribute_end + ) + ); + } + + private static function processDeprecatedElement( + DomElement $deprecated_element_xml, + string $file_contents, + self $config, + string $config_path + ): void { + $line = $deprecated_element_xml->getLineNo(); + assert($line > 0); + + $offset = self::lineNumberToByteOffset($file_contents, $line); + $element_start = strpos($file_contents, $deprecated_element_xml->localName, $offset) ?: 0; + $element_end = $element_start + strlen($deprecated_element_xml->localName) - 1; + + $config->config_issues[] = new ConfigIssue( + 'Element "' . $deprecated_element_xml->localName . '" is deprecated ' + . 'and is going to be removed in the next major version', + new Raw( + $file_contents, + $config_path, + basename($config_path), + $element_start, + $element_end + ) + ); + } + private static function processConfigDeprecations( self $config, DOMDocument $dom_document, @@ -770,15 +823,11 @@ private static function processConfigDeprecations( ): void { $config->config_issues = []; - // Attributes to be removed in Psalm 5 - $deprecated_attributes = [ - 'allowCoercionFromStringToClassConst', - 'allowPhpStormGenerics', - ]; + // Attributes to be removed in Psalm 6 + $deprecated_attributes = []; - $deprecated_elements = [ - 'exitFunctions', - ]; + /** @var list */ + $deprecated_elements = []; $psalm_element_item = $dom_document->getElementsByTagName('psalm')->item(0); assert($psalm_element_item !== null); @@ -786,24 +835,7 @@ private static function processConfigDeprecations( 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; - - $config->config_issues[] = new ConfigIssue( - 'Attribute "' . $attribute->name . '" is deprecated ' - . 'and is going to be removed in the next major version', - new Raw( - $file_contents, - $config_path, - basename($config_path), - $attribute_start, - $attribute_end - ) - ); + self::processDeprecatedAttribute($attribute, $file_contents, $config, $config_path); } } @@ -814,25 +846,7 @@ private static function processConfigDeprecations( ); if ($deprecated_elements_xml->length) { $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 Raw( - $file_contents, - $config_path, - basename($config_path), - $element_start, - $element_end - ) - ); + self::processDeprecatedElement($deprecated_element_xml, $file_contents, $config, $config_path); } } }