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?

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top