Skip to content

Update php snippet due to PSR-12 #548

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions snippets/php/php.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
{
"class …": {
"class full": {
"prefix": "classfull",
"body": [
"class ${1:ClassName} ${2:extends ${3:AnotherClass}} ${4:implements ${5:Interface}}",
"{",
"\t$0",
"}",
""
],
"description": "Class full definition"
},
"class ...": {
"prefix": "class",
"body": [
"class ${1:ClassName} ${2:extends ${3:AnotherClass}} ${4:implements ${5:Interface}} {",
"${1|final readonly ,final ,readonly |}class ${2:ClassName}",
"{",
"\t$0",
"}",
""
],
"description": "Class definition"
"description": "Class short definition"
},
"PHPDoc class …": {
"prefix": "doc_class",
"body": [
"/**",
" * ${6:undocumented class}",
" */",
"class ${1:ClassName} ${2:extends ${3:AnotherClass}} ${4:implements ${5:Interface}} {",
"class ${1:ClassName} ${2:extends ${3:AnotherClass}} ${4:implements ${5:Interface}}",
"{",
"\t$0",
"}",
""
Expand All @@ -25,7 +38,8 @@
"function __construct": {
"prefix": "con",
"body": [
"public function __construct(${1: priarg}) {",
"public function __construct(${1: priarg})",
"{",
"}"
],
"description": "Create __construct method using the last php syntax."
Expand All @@ -40,7 +54,8 @@
"function __construct (php 7 or lower)": {
"prefix": "con7",
"body": [
"public function __construct(${1:${2:Type} \\$${3:var}${4: = ${5:null}}}) {",
"public function __construct(${1:${2:Type} \\$${3:var}${4: = ${5:null}}})",
"{",
"\t\\$this->${3:var} = \\$${3:var};$0",
"}"
],
Expand All @@ -66,7 +81,8 @@
"${7: * @return ${8:type}}",
"${9: * @throws ${10:conditon}}",
" **/",
"${11:public }function ${12:FunctionName}(${13:${14:${4:Type} }\\$${5:var}${15: = ${16:null}}}) {",
"${11:public }function ${12:FunctionName}(${13:${14:${4:Type} }\\$${5:var}${15: = ${16:null}}})",
"{",
"\t${0:# code...}",
"}"
],
Expand All @@ -80,7 +96,8 @@
"function …": {
"prefix": "fun",
"body": [
"${1:public }function ${2:FunctionName}(${3:${4:${5:Type} }\\$${6:var}${7: = ${8:null}}}) {",
"${1:public }function ${2:FunctionName}(${3:${4:${5:Type} }\\$${6:var}${7: = ${8:null}}}): ${9:void}",
"{",
"\t${0:# code...}",
"}"
],
Expand Down Expand Up @@ -174,12 +191,12 @@
"description": "Foreach loop"
},
"$… = array (…)": {
"prefix": "array",
"prefix": "arrayold",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose for renaming these array initializers?

Copy link
Author

@oldy777 oldy777 Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, because the short array syntax is the default today, and the old syntax is only used for older versions of PHP.

"body": "\\$${1:arrayName} = array('$2' => $3${4:,} $0);",
"description": "Array initializer"
},
"$… = […]": {
"prefix": "shorray",
"prefix": "array",
"body": "\\$${1:arrayName} = ['$2' => $3${4:,} $0];",
"description": "Array initializer"
},
Expand Down