1

I generate my entities using doctrine mapping in symfony2, and get this code:

/**
 * Get active
 *
 * @return boolean
 */
public function getActive() {
    return $this->active;
}

Using jenkins and PMD plugin, they throw BooleanGetMethodName warnings and suggest that because getActive function return boolean, it should be renamed to isActive or hasActive.

I have a lot of files that have this warning. Is it good to suppress the warnings? If yes, how? Or should I replace all functions name returning boolean value in symfony2 entity to follow jenkins and PMD rule?

ihsan
  • 2,279
  • 20
  • 36
  • Yes, every boolean value sould have an isValue or hasValue "getter" – Emii Khaos May 14 '13 at 10:14
  • @Pazi thank you for responding. I understand it is logical to do that. But could you add more explanation? Is there any standards like html from w3c? – ihsan May 14 '13 at 10:25
  • Unfortunatel not, but this is a generally coding convetion, which every project clearly follows. Look at symfony itself – Emii Khaos May 14 '13 at 10:34

1 Answers1

1

By PMD you mean PHP Mess Detector?

If so, since you have a setup with Jenkins and PHP Mess Detector, I assume you actually care about code smells and readability.

With that in mind, my advice to you is: rename all of your boolean methods to follow the isSomething() or hasSomething() conventions.

Its important to notice though what code convention guide you follow.

That is very simple and quick to achieve, and will give you lots of benefits, such as:

  • Possible bugs. Bugs are not always wrongly written code. A lot of times, poor conditions or bad management of scope can generate pretty hard to find bugs.

  • Suboptimal code. Bad looking code can and most likely will be dificult to read. This is suboptimal code.

  • Overcomplicated expressions

  • Unused parameters, methods or properties
Daniel Ribeiro
  • 10,156
  • 12
  • 47
  • 79