ProductVariation price getters don't implement interface correctly - missing return statement

Created on 26 April 2023, over 1 year ago
Updated 1 June 2023, over 1 year ago

Describe your bug or feature request.

class ProductVariation extends CommerceContentEntityBase implements ProductVariationInterface {
  // ...

  /**
   * {@inheritdoc}
   */
  public function getListPrice() {
    if (!$this->get('list_price')->isEmpty()) {
      return $this->get('list_price')->first()->toPrice();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getPrice() {
    if (!$this->get('price')->isEmpty()) {
      return $this->get('price')->first()->toPrice();
    }
  }

  // ...
}

As ProductVariationInterface defines these getters with a return type of Price|null and they don't have a return statement for the else branch, they cause a "Missing return statement" warning in the IDE and when used the return type is reported as Price|null|void.

If a bug, provide steps to reproduce it from a clean install.

There is no need to do an install, this can be found by static code analysis.

Steps to solve the bug

Return null for the else branch.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Product

Created by

🇦🇹Austria mvonfrie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024