BooleanGetMethodName warning in phpmd

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?

Answers


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

Need Your Help

String.Format() TimeSpan vs DateTime

c# string-formatting timespan

Why do I need to escape the delimiters when I format a TimeSpan, while it's not needed when I format a DateTime?

Function.tupled and placeholder syntax

scala scala-2.8

I have seen this usage of Function.tupled example in another answer: Map(1 -> "one", 2 -> "two") map Function.tupled(_ -> _.length).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.