Skip to content

Commit

Permalink
Add php 8 snippets
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
soulshined committed Feb 21, 2023
1 parent 6c5a84a commit 4371e41
Showing 1 changed file with 81 additions and 6 deletions.
87 changes: 81 additions & 6 deletions extensions/php/snippets/php.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@
"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": [
Expand All @@ -74,11 +98,6 @@
],
"description": "Class definition"
},
"class const": {
"prefix": "class_const",
"body": "${1|public ,private ,protected |}const ${2:NAME} = $3;",
"description": "Class constant"
},
"class __construct": {
"prefix": "construct",
"body": [
Expand Down Expand Up @@ -106,7 +125,39 @@
"\t${0:# code...}",
"}"
],
"description": "Function"
"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"
},
"dynamic property class": {
"prefix": "dynamic_class",
"body": [
"#[\\\\AllowDynamicProperties]",
"${1:${2|final ,readonly |}}class ${3:${TM_FILENAME_BASE}}${4: extends ${5:AnotherClass}} ${6:implements ${7:Interface}}",
"{",
"\t$0",
"}"
]
},
"enum": {
"prefix": "enum",
"body": [
"enum $1 {",
"\tcase $2;$0",
"}"
]
},
"enum backed": {
"prefix": "enum_backed",
"body": [
"enum $1: ${2|string,int|} {",
"\tcase $3;$0",
"}",
],
"description": "Backed enum"
},
"define(…, …)": {
"prefix": "def",
Expand Down Expand Up @@ -166,6 +217,15 @@
],
"description": "Foreach loop"
},
"foreach enum": {
"prefix": "foreach_enum",
"body": [
"foreach ($1::cases() as \\$case) {",
"\t$0",
"}"
],
"description": "Foreach enum case loop"
},
"function": {
"prefix": "fun",
"body": [
Expand Down Expand Up @@ -244,6 +304,16 @@
],
"description": "Nowdoc"
},
"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",
Expand Down Expand Up @@ -335,6 +405,11 @@
],
"description": "Folding Region Start"
},
"sensitive param": {
"prefix": "sensitive_param",
"body": "#[\\\\SensitiveParameter] ${1:Type} $${2:var}${3: = ${4:null}}$5",
"description": "Parameter definition"
},
"switch …": {
"prefix": "switch",
"body": [
Expand Down

0 comments on commit 4371e41

Please sign in to comment.