vscode/extensions/php/snippets/php.code-snippets
David Freer 89636b9b4c
PHP Snippets Quality of Life and Continuity (#174889)
* QoL & continuity update to existing php snippets

- Sorted snippets by snippet title for discoverability
- Removed all doc comments from non 'doc_' prefixed snippets
- Added doc_trait for continuity with other patterns
- Updated snippet prefixes
	- Add kvp to keyval
	- Prefixed fun with class_
	- Changed doc_param to doc_var
	- Qualified 'con' to 'constructor' to not be confused with const
- Updated class snippet to default the 'class' placeholder to the file's base name
- Add snippet choices for private, public, protected where appropriate
- Add an additional tab stop to end of functions for additional args/params
- Remove array kvps since arrays can be associative or just values

* Add try catch finally php snippet

* Add param php snippet

* Add php func snippets

- Add fun for a general function out of scope of class
- Add fun_anonymous for anonymous functions
- Add fun_arrow for arrow functions

* Add promotion style constructor to php snippets

* Add property snippet to php snippets

* Add spaceship snippet to php snippets

* Add goto snippet to php snippets

* Add class_const snippet to php snippets

* Add here/now doc snippets to php snippets

* Add namespace related snippets to php snippets

* Add superglobal snippets to php snippets

* Add php 8 snippets

- Add match expression
- Add Attribute snippets
  - Add sensitive parameter
  - Add attribute target
  - Add attribute with target
- Rename class_const to const
- Add Dynamic Property Class snippet
- Add enum snippets
  - Basic Enum
  - Backed Enum
  - foreach enum

* Merge master to resolve conflict

* Remove php snippets as candidates

- Remove heredoc
- Remove nowdoc
- Remove php super global snippets
- Remove namespace_path
- Remove ethis (echo $this->)
- Remove try/catch finally

* Trim snippets

---------

Co-authored-by: Rob Lourens <roblourens@gmail.com>
2023-05-18 14:46:36 -07:00

333 lines
7.0 KiB
Plaintext

{
"$… = ( … ) ? … : …": {
"prefix": "if?",
"body": "$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b} ;",
"description": "Ternary conditional assignment"
},
"$… = array (…)": {
"prefix": "array",
"body": "$${1:arrayName} = array($0);",
"description": "Array initializer"
},
"$… = […]": {
"prefix": "shorray",
"body": "$${1:arrayName} = [$0];",
"description": "Array initializer"
},
"… => …": {
"prefix": "keyval,kvp",
"body": "'$1' => $2$0",
"description": "Key-Value pair"
},
"$a <=> $b": {
"prefix": "spaceship",
"body": "(${1:$$a} <=> ${2:$$b} === ${3|0,1,-1|})",
"description": "Spaceship equality check"
},
"attribute": {
"prefix": "attr",
"body": [
"#[\\\\Attribute]",
"class ${1:My}Attribute${2: extends ${3:MyOther}Attribute} {",
"\t$0",
"}"
],
"description": "Attribute"
},
"attribute target": {
"prefix": "attr_target",
"body": "\\Attribute::${1|TARGET_ALL,TARGET_CLASS,TARGET_FUNCTION,TARGET_METHOD,TARGET_PROPERTY,TARGET_CLASS_CONSTANT,TARGET_PARAMETER,IS_REPEATABLE|}$0"
},
"attribute with target": {
"prefix": "attr_with_target",
"body": [
"#[\\\\Attribute(\\Attribute::${1|TARGET_ALL,TARGET_CLASS,TARGET_FUNCTION,TARGET_METHOD,TARGET_PROPERTY,TARGET_CLASS_CONSTANT,TARGET_PARAMETER,IS_REPEATABLE|}$2)]",
"class ${3:My}Attribute${4: extends ${5:MyOther}Attribute} {",
"\t$0",
"}"
],
"description": "Attribute - Chain targets with attr_target snippet"
},
"case …": {
"prefix": "case",
"body": [
"case '${1:value}':",
"\t${0:# code...}",
"\tbreak;"
],
"description": "Case Block"
},
"class …": {
"prefix": "class",
"body": [
"${1:${2|final ,readonly |}}class ${3:${TM_FILENAME_BASE}}${4: extends ${5:AnotherClass}} ${6:implements ${7:Interface}}",
"{",
"\t$0",
"}",
""
],
"description": "Class definition"
},
"class function …": {
"prefix": "class_fun",
"body": [
"${1|public ,private ,protected |}${2: static }function ${3:FunctionName}(${4:${5:${6:Type} }$${7:var}${8: = ${9:null}}}$10) : ${11:Returntype}",
"{",
"\t${0:# code...}",
"}"
],
"description": "Function for classes, traits and enums"
},
"const": {
"prefix": "const",
"body": "${1|public ,private ,protected |}const ${2:NAME} = $3;",
"description": "Constant for classes, traits, enums"
},
"enum": {
"prefix": "enum",
"body": [
"enum $1 {",
"\tcase $2;$0",
"}"
]
},
"define(…, …)": {
"prefix": "def",
"body": [
"define('$1', ${2:'$3'});",
"$0"
],
"description": "Definition"
},
"do … while …": {
"prefix": "do",
"body": [
"do {",
"\t${0:# code...}",
"} while (${1:$${2:a} <= ${3:10}});"
],
"description": "Do-While loop"
},
"for …": {
"prefix": "for",
"body": [
"for ($${1:i}=${2:0}; $${1:i} < $3; $${1:i}++) { ",
"\t${0:# code...}",
"}"
],
"description": "For-loop"
},
"foreach …": {
"prefix": "foreach",
"body": [
"foreach ($${1:variable} as $${2:key}${3: => $${4:value}}) {",
"\t${0:# code...}",
"}"
],
"description": "Foreach loop"
},
"function": {
"prefix": "fun",
"body": [
"function ${1:FunctionName}($2)${3: : ${4:Returntype}} {",
"\t$0",
"}"
],
"description": "Function - use param snippet for parameters"
},
"anonymous function": {
"prefix": "fun_anonymous",
"body": [
"function ($1)${2: use ($${3:var})} {",
"\t$0",
"}"
],
"description": "Anonymous Function"
},
"if …": {
"prefix": "if",
"body": [
"if (${1:condition}) {",
"\t${0:# code...}",
"}"
],
"description": "If block"
},
"if … else …": {
"prefix": "ifelse",
"body": [
"if (${1:condition}) {",
"\t${2:# code...}",
"} else {",
"\t${3:# code...}",
"}",
"$0"
],
"description": "If Else block"
},
"match": {
"prefix": "match",
"body": [
"match (${1:expression}) {",
"\t$2 => $3,",
"\t$4 => $5,$0",
"}"
],
"description": "Match expression; like switch with identity checks. Use keyval snippet to chain expressions"
},
"param": {
"prefix": "param",
"body": "${1:Type} $${2:var}${3: = ${4:null}}$5",
"description": "Parameter definition"
},
"property": {
"prefix": "property",
"body": "${1|public ,private ,protected |}${2|static ,readonly |}${3:Type} $${4:var}${5: = ${6:null}};$0",
"description": "Property"
},
"PHPDoc class …": {
"prefix": "doc_class",
"body": [
"/**",
" * ${8:undocumented class}",
" */",
"${1:${2|final ,readonly |}}class ${3:${TM_FILENAME_BASE}}${4: extends ${5:AnotherClass}} ${6:implements ${7:Interface}}",
"{",
"\t$0",
"}",
""
],
"description": "Documented Class Declaration"
},
"PHPDoc function …": {
"prefix": "doc_fun",
"body": [
"/**",
" * ${1:undocumented function summary}",
" *",
" * ${2:Undocumented function long description}",
" *",
"${3: * @param ${4:Type} $${5:var} ${6:Description}}",
"${7: * @return ${8:type}}",
"${9: * @throws ${10:conditon}}",
" **/",
"${11:public }function ${12:FunctionName}(${13:${14:${4:Type} }$${5:var}${15: = ${16:null}}}17)",
"{",
"\t${0:# code...}",
"}"
],
"description": "Documented function"
},
"PHPDoc param …": {
"prefix": "doc_param",
"body": [
"* @param ${1:Type} ${2:var} ${3:Description}$0"
],
"description": "Paramater documentation"
},
"PHPDoc trait": {
"prefix": "doc_trait",
"body": [
"/**",
" * $1",
" */",
"trait ${2:TraitName}",
"{",
"\t$0",
"}",
""
],
"description": "Trait"
},
"PHPDoc var": {
"prefix": "doc_var",
"body": [
"/** @var ${1:Type} $${2:var} ${3:description} */",
"${4:protected} $${2:var}${5: = ${6:null}};$0"
],
"description": "Documented Class Variable"
},
"Region End": {
"prefix": "#endregion",
"body": [
"#endregion"
],
"description": "Folding Region End"
},
"Region Start": {
"prefix": "#region",
"body": [
"#region"
],
"description": "Folding Region Start"
},
"switch …": {
"prefix": "switch",
"body": [
"switch (\\$${1:variable}) {",
"\tcase '${2:value}':",
"\t\t${3:# code...}",
"\t\tbreak;",
"\t$0",
"\tdefault:",
"\t\t${4:# code...}",
"\t\tbreak;",
"}"
],
"description": "Switch block"
},
"trait …": {
"prefix": "trait",
"body": [
"trait ${1:TraitName}",
"{",
"\t$0",
"}",
""
],
"description": "Trait"
},
"Try Catch Block": {
"prefix": "try",
"body": [
"try {",
"\t${1://code...}",
"} catch (${2:\\Throwable} ${3:\\$th}) {",
"\t${4://throw \\$th;}",
"}"
],
"description": "Try catch block"
},
"use function": {
"prefix": "use_fun",
"body": "use function $1;"
},
"use const": {
"prefix": "use_const",
"body": "use const $1;"
},
"use grouping": {
"prefix": "use_group",
"body": [
"use${1| const , function |}$2\\{",
"\t$0,",
"}"
],
"description": "Use grouping imports"
},
"use as ": {
"prefix": "use_as",
"body": "use${1| const , function |}$2 as $3;",
"description": "Use as alias"
},
"while …": {
"prefix": "while",
"body": [
"while (${1:$${2:a} <= ${3:10}}) {",
"\t${0:# code...}",
"}"
],
"description": "While-loop"
}
}