Skip to content

Instantly share code, notes, and snippets.

@m1roff
Last active February 20, 2022 19:17
Show Gist options
  • Save m1roff/1ca2f4afb4dcbc06d3372ee078c0a7ea to your computer and use it in GitHub Desktop.
Save m1roff/1ca2f4afb4dcbc06d3372ee078c0a7ea to your computer and use it in GitHub Desktop.
PhpStorm. LiveTemlate. Generate comments for ENUM

Add DocBlock for the class when using myclabs/php-enum library. Sippet for PHPStorm

Snippet to fast create docblock for enum using library https://github.com/myclabs/php-enum.

  1. PHPStorm > Settings > Editor > Live Templates
  2. Add new snippet
  3. Abbreviation: cEnumDocBlock
  4. Description: Create ENUM docblock
  5. Template Text:
/**
$CLASS_NAME$
 */$END$
  1. Edit variables
  2. Expression: groovyScript("File inputFile = new File(_1);LineNumberReader reader = inputFile.newReader(); def somValue = ''; while ((line = reader.readLine()) != null) { def cleanLine = line.trim(); def m = cleanLine =~ /private const\\\s(.*)\\\s=/; if (m.size() > 0) { somValue = somValue + ' * @method static ' + _2 + ' ' + m[0][1] + '''()\n'''; }; }; return somValue + '';", filePath(), phpClassName())
File inputFile = new File(_1);LineNumberReader reader = inputFile.newReader();
def outputLine = '';
while ((line = reader.readLine()) != null) {
def cleanLine = line.trim();
def m = cleanLine =~ /private const\\\s(.*)\\\s=/;
if (m.size() > 0) {
outputLine = outputLine + ' * @method static ' + _2 + ' ' + m[0][1] + '''()\n''';
};
};
return outputLine + '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment