Skip to content

Commit

Permalink
Remove the optional support for ancient PHP versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Dec 4, 2024
1 parent 643206f commit f95f4c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 43 deletions.
11 changes: 0 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@
"type": "boolean",
"default": true,
"description": "Add type declarations (also known as type hints) to autocompleted callback functions"
},
"vscode-wordpress-hooks.typeDeclarations.olderPhpVersionSupport": {
"type": "string",
"description": "PHP 7.2 or higher is required to support the full set of type declaration features. If you need to support an older version of PHP, select it here and only the types available in that version of PHP will be used",
"default": "None",
"enum": [
"None",
"7.1",
"7.0",
"5.6"
]
}
}
}
Expand Down
36 changes: 4 additions & 32 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ interface tagType {
function getTagType(
tag: Tag,
): tagType | null {
const typeDeclarationsSupport = getMinPHPVersion();

// https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
const allowedTypes: { [key: string]: number } = {
self: 5.0,
Expand All @@ -134,11 +132,6 @@ function getTagType(
nullable: false,
};

// Type declarations disabled? Bail.
if (!typeDeclarationsSupport) {
return null;
}

// No type info? Bail.
if (!tag.types) {
return null;
Expand All @@ -147,7 +140,7 @@ function getTagType(
const types = [...tag.types];

// Handle nullable type.
if (types.length === 2 && typeDeclarationsSupport >= 7.1) {
if (types.length === 2) {
if (types[0] === 'null') {
types.splice(0, 1);
typeData.nullable = true;
Expand Down Expand Up @@ -195,7 +188,7 @@ function getTagType(
}

// Check the allowed types, ignoring unknown types such as class and interface names.
if (allowedTypes[type] && (allowedTypes[type] > typeDeclarationsSupport)) {
if (allowedTypes[type]) {
return null;
}

Expand All @@ -207,29 +200,9 @@ function getTagType(
function getReturnType(
tag: Tag,
) : tagType | null {
// Return type declarations require PHP 7 or higher.
if (getMinPHPVersion() < 7) {
return null;
}

return getTagType(tag);
}

function getMinPHPVersion() : number {
const typeDeclarationsEnabled: boolean = vscode.workspace.getConfiguration(extensionName).get('typeDeclarations.enable') ?? true;
const typeDeclarationsSupportSetting: string = vscode.workspace.getConfiguration(extensionName).get('typeDeclarations.olderPhpVersionSupport') ?? '';

if (!typeDeclarationsEnabled) {
return 0;
}

if (!typeDeclarationsSupportSetting || typeDeclarationsSupportSetting === 'None') {
return 999;
}

return parseFloat(typeDeclarationsSupportSetting);
}

interface contextualPosition {
symbol: vscode.DocumentSymbol | null;
inNamespace: boolean;
Expand Down Expand Up @@ -380,9 +353,8 @@ export function activate(
docblockLines.push(` * @return ${params[0].types?.join('|') || ''} ${params[0].content}`);
} else {
const actionArgsString = snippetArgsString ? ` ${snippetArgsString} ` : '';
returnTypeString = (getMinPHPVersion() >= 7.1) ? ' : void' : '';
snippetCallback = `(${actionArgsString})${returnTypeString} {\n\t\${1}\n}`;
documentationCallback = `(${docArgsString})${returnTypeString} {\n}`;
snippetCallback = `(${actionArgsString}) : void {\n\t\${1}\n}`;
documentationCallback = `(${docArgsString}) : void {\n}`;
}

docblockLines.push(' */');
Expand Down

0 comments on commit f95f4c9

Please sign in to comment.