Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropped removed config entries #7272

Merged
merged 1 commit into from Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 0 additions & 10 deletions config.xsd
Expand Up @@ -32,16 +32,6 @@
<xs:attribute name="serializer" type="xs:string" />

<xs:attribute name="addParamDefaultToDocblockType" type="xs:boolean" default="false" />

<xs:attribute name="allowCoercionFromStringToClassConst" type="xs:boolean" default="false">
<xs:annotation>
<!-- note: for PHPStorm to mark the attribute as deprecated the doc entry has to be *single line* and start with the word `deprecated` -->
<xs:documentation xml:lang="en">
Deprecated. Has no effect since Psalm 3 and is going to be removed in Psalm 5.
</xs:documentation>
</xs:annotation>
</xs:attribute>

<xs:attribute name="allowFileIncludes" type="xs:boolean" default="true" />
<xs:attribute name="allowStringToStandInForClass" type="xs:boolean" default="false" />
<xs:attribute name="checkForThrowsDocblock" type="xs:boolean" default="false" />
Expand Down
104 changes: 59 additions & 45 deletions src/Psalm/Config.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -770,40 +823,19 @@ 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<string> */
$deprecated_elements = [];

$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;

$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);
}
}

Expand All @@ -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);
}
}
}
Expand Down