Method in PHP have line limits?

4
  

The method size is 22 rows. (20 Allowed)

NetBeans gives me this "warning", why? Is it a PHP rule?

What's best:

  • A great method with all the code it needs.
  • Splitting this code into smaller methods
  • Is there an adequate number of rows in a method?
  • asked by anonymous 03.07.2017 / 22:55

    3 answers

    3

    This is a suggestion of netbeans there is no limit of rows or characters for a method. Ideally, it solves only one problem, or has only one responsibility.

      

    1) A great method with all the code it needs.

    In this situation there is a great possibility that the method is doing several things.

      

    2) Split this code into smaller methods

    In some cases it is the best solution.

      

    3) Is there an adequate number of rows in a method?

    No.

        
    03.07.2017 / 22:58
    0

    The rray's response is good, just add one thing: You leave the less specific methods have to do with code reuse, with less specific methods you can reuse them more.

    Perhaps this is best seen when you are in the design part of the application or later when you are going to review the code and see that there is a lot of repetition that could be done once and reused more than once.

        
    03.07.2017 / 23:07
    0
      

    NetBeans gives me this "warning", why? Is it a PHP rule?

    As per this thread in% of NetBeans , is only a bug tracking that can be disabled in hint .

    And no, this is not a rule of Editor > Hints . For PHP we usually follow PHP , acronym for PSR , where there are community-defined patterns to standardize development with language. In your specific question, there is the topic PHP Standards Recommendations which reads as follows:

    • The line should not have a strict limit on its length. The maximum must be 120 characters, displaying 2.3. Lines but not warning . Ideally, it should be 80 characters or less, but if necessary you can break it.
    • One command per line;
      
  • A great method with all the code it needs.
  •   
  • Splitting this code into smaller methods
  •   
  • Is there an adequate number of rows in a method?
  •   

    These three questions are more about development patterns and architectures, so I'll try to respond in a single shot:

    As this thread in software engineering / Robert in his book, error , says:

      

    The first rule of functions is that they must be small. The second rule is that they should be smaller than that. They should not have more than 100 lines. They should hardly go beyond the 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 analyze it better, check to see if it goes according to Clean Code: A Handbook of Agile Software Craftsmanship , so Robert Martin says she should be responsible for only one thing.

    The division into smaller codes also includes the following topics:

    • Testability
    • Cohesion and Coupling
    • Understanding

    Reading tip:

    04.07.2017 / 00:59