1

I found in some drupal commerce modules class comments in way I haven't seen so far

/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
/** @var \Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway\ExpressCheckoutInterface $payment_gateway_plugin */
$payment_gateway_plugin = $payment->getPaymentGateway()->getPlugin();

I am not sure what to google to get to know more about this, why was it used like that and is this annotation or just plan comment?

2
  • 2
    It helps the IDE understand what the object is.
    – Kevin
    Feb 13, 2019 at 13:05
  • I rephrased my question, I also tried the code without those lines, seems it works.
    – Blissful
    Feb 13, 2019 at 13:32

1 Answer 1

1

I checked more about annotations and it doesnt makes sense to have them in places other then outside the class, as stated on d.org, so this is just plain comment for IDE's to connect what is used there.

In addition, there is a performance bonus as it makes Drupal use less memory when discovering plugins. The original implementation had a getInfo() method on each class, similar to Drupal 7 test classes. This meant each class had to be loaded into memory to get its information and the memory was not freed until the end of the request, thus greatly increasing the peak memory requirement for PHP. Instead, the implementation used by Drupal to parse the annotation simply tokenizes the text of the file without including it as a PHP file, so memory use is minimized.

2

Not the answer you're looking for? Browse other questions tagged or ask your own question.