0

How should i reference on a PHPdoc block that if the variable is not present it will check a dotenv setting for it?

 /**
 * Class constructor.
 *
 *  Created Class Object.
 *
 * @param null $url     - access url for api
 */

public function __construct($url = null)
{
     if (! isset($url)) {
        $url = env('CLASS_URL', null);
    }
}
Danilo Kobold
  • 2,562
  • 1
  • 21
  • 31
  • Sounds very case specific. I'd just note it down after the `access url for api` part – apokryfos Oct 08 '19 at 15:23
  • It tries specific parameter and if not present checks .env. I understand it is not a language feature but it is far from specific – Danilo Kobold Oct 08 '19 at 15:26
  • 1
    I don't think there's specific PHPDoc syntax to indicate what it does if the parameter is not provided other than saying what the default value is. – apokryfos Oct 08 '19 at 15:29

2 Answers2

1

Presumably that env() function is one you have defined. As such, I'd use the @see env() tag to highlight that it is used to find a value when it's not given via argument.

ashnazg
  • 6,558
  • 2
  • 32
  • 39
0

You can split it by making a static createFromEnv() with a formless description which creates the instance. This way it's more obvious from where $url is taken.

Disadvantage is that the creator must make the decision explicitly whether to call createFromEnv or __construct.

MonkeyMonkey
  • 826
  • 1
  • 6
  • 19