Netbeans gives me this "warning," so why? It’s a PHP rule?
According to this thread in the bug tracking
of Netbeans, is just one hint
which can be disabled in Editor > Hints
.
And no, that’s not a rule of PHP
. To the PHP
we usually follow the PSR
, acronym for PHP Standards Recommendations
, where there are standards defined by the community to standardize development with language. In your specific doubt, there is the topic 2.3. Lines
which says the following:
- The line should not have a strict limit on its length. The maximum should be 120 characters, displaying a
warning
but not causing error
. The ideal is that it is 80 characters or less, but if necessary it can be broken.
- One command per line;
- A great method with all the code he needs.
- Split this code into smaller methods
- There is an appropriate number of lines in a method?
These three questions go deeper into development patterns and architectures, so I’ll try to answer in a single shot:
According to this thread in Engineering / se software, Robert Martin in his book, Clean Code: A Handbook of Agile Software Craftsmanship
, says:
The first rule of function is that they should be small. The second rule is that they should be smaller than that. They should not have more than 100 lines. They should hardly exceed 20 lines.
If a method is large and there really is a need for it, it is a specific case of your software. But if you can take a closer look at it, make sure she comes in according to Princípio da Responsabilidade Única
, also Robert Martin says that she should be responsible for only one thing.
The division into smaller codes also comprises the following topics:
- Testability
- Cohesion and Coupling
- Understanding
Reading tip:
Related: https://answall.com/a/31473/101
– Maniero
I recommend the book Clean Code, by Robert Martin, it addresses in a very clear way the best practices for creating classes, methods, and several other extremely important points for an agile development
– Marcio Mazzucato