Jump to content

Recommended Posts

I always struggle with keeping my annotations pretty.  Just about ever IDE beautifies PHP, there are many online PHP beautifiers, and notepad++ and other apps are available.  None of them seem to work with annotations.  Also, would like to validate them at the same time.

Anyone know of any plugins or websites which do this?  I would be fine with just cutting and pasting just the comment block and it need not format the entire PHP script (I probably wouldn't even use the PHP portions as git would probably see changes).

If nothing is available, suppose I could create one myself.  Before doing so, however, would like to better understand best practices.  For instance, how many spaces for indentations, what is acceptable to put inline (i.e. the @ORM\Table item should definitely not be on a single line), etc.

Thank!

/**
* @ORM\Entity()
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_position_serie", columns={"test_chart_id", "position"}), @ORM\UniqueConstraint(name="unique_name_serie", columns={"test_chart_id", "name"})})
* @ApiResource(
*     collectionOperations={
*      "get" = {
*          "method"="GET",
*    },
*      "post" = {
*    }
* },
*     itemOperations={
*      "get" = {
*              "openapi_context" = {
*                  "parameters" = {
*                      {
*                          "name" = "nameOfQueryParameter",
*                          "in" = "query",
*                          "description" = "Description goes here",
*                          "schema" = {
*                              "type" = "string"
*                          }
*                      }
*                  }
*               }
*    },
*      "put" = {
*    },
*      "patch" = {
*    },
*      "delete" = {
*    }
* }
* )
*/

 

Link to comment
https://forums.phpfreaks.com/topic/312741-formatting-annotations/
Share on other sites

I don't use annotations, so N/A.

PHPStorm will apply some basic formatting to doc blocks, but trying your sample annotation it doesn't seem to do anything with it outside of wrapping long lines.

As far as style, do whatever you like, just be consistent.

On 5/23/2021 at 11:30 PM, kicken said:

I don't use annotations, so N/A.

Neither did I for quite a while based on your advice.  My main reason for starting to use them was being able to see all relevant information in one place (i.e. database and serialization).   That being said, have special comments in code still kind of annoys me, and I like having this content divorced from the code.  Still find it kind of odd that someone hasn't come up with a annotation formatter/validator.   Guess much is based on what is using them, but still...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.