phpwordpresseditorneovimphpdoc

How to automatic add and update a file header comment block?


Many source files have an prominent file header at the beginning of the document. For example:

<?php
/**
 * Template for header
 *
 * Description
 *
 * @Author: Author
 * @Date: 2020-11-26 09:19:12
 * @Last Modified by:   Author
 * @Last Modified time: 2020-11-27 10:08:51
 *
 * @package WordPress
 */
?>

How are these comments added? Possible solutions I can think of are:

Does anyone know a solutions which works in the most editors?


Solution

  • Adding header comments it's usually automated process.

    The simplest way is to configure header comment for each new PHP file in your IDE. For example PhpStorm has File templates for this.

    Another option these are tools like PHP CS Fixer. You configure header comment template and add it to all files in your project using one simple command.

    Tools like PHP CS Fixer it's a better way, because if you want to change something in your comment, you just need to update template in config file and run console command again. It will update all files in your project.