6

I created a PHP class in PhpStorm and allowed the IDE to auto-generate the DocBlock for the class. It included a package tag that exactly matched the namespace of the file as follows:

<?php
namespace frontend\controllers;

/**
 * Class MethodController
 * @package frontend\controllers
 */
class MethodController extends BaseRestController 
{
}

I don't presently care to generate PHPDocumentor output, but I may want to at some point, so I would like to understand how @package is used. What surprises me is the message that PHP_CodeSniffer provided for this tag:

[phpcs] Package name "frontend\controllers" is not valid; consider "Frontendcontrollers" instead

Do I need to create some sort of table of contents to satisfy PHP_CodeSniffer?

Another perplexing twist is this quote from the PHPDoc website:

If, across the board, both logical and functional subdivisions are equal is it NOT RECOMMENDED to use the @package tag, to prevent maintenance overhead.

If I understand this correctly, there is no benefit in making the package exactly equal to the namespace. Why did PhpStorm provide this tag?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Schparky
  • 429
  • 4
  • 10
  • 1
    *"Why did PhpStorm provide this tag?"* No ideas (it does not add for me .. but my PhpStorm setup is really old (using it from v0.6 or so). Check your `Settings / Preferences | Editor | File and Code Templates` -- you should find a template for class PHPDoc -- it might be there. P.S. I personally see no reason in `@package` tag at all. Namespace itself does the good job already. – LazyOne Oct 28 '18 at 10:56
  • @LazyOne I've a new set-up and the template includes `#if (${NAMESPACE}) * @package ${NAMESPACE} #end`. – Álvaro González Nov 01 '18 at 10:03
  • @LazyOne This is great advice as I now can auto-generate a class docblock without this tag when making a new PHP Class, so thankyou. On the subject of the original question though, is it possible to alter the PHPDoc template for annotating classes? I know you can do some options for method annotations under 'Code Style' – Scott Anderson Jan 12 '21 at 09:04
  • @ScottAnderson All code templates that can be customized will be there: `Settings/Preferences | Editor | File and Code Templates`. Code Style is more about an order of elements/spacing etc. – LazyOne Jan 12 '21 at 09:22
  • @LazyOne Ah found it! In the 'Code' tab of that setting pane I see, thanks :) – Scott Anderson Jan 12 '21 at 09:37
  • Sorry, not really on topic, but can you also tell me how I input a live template into these File and Code templates? Can see an example here but I don't understand https://www.jetbrains.com/help/phpstorm/settings-file-and-code-templates.html#controls – Scott Anderson Jan 12 '21 at 09:44

0 Answers0