How many lines of PHP code is too many for one file?

前端 未结 8 2183
日久生厌
日久生厌 2021-02-20 15:55

I\'m creating a PHP file that does 2 mysql database calls and the rest of the script is if statements for things like file_exists and other simple variables. I have about 2000

8条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 16:16

    I don't know any useful way to split code that's that simple, particularly if it all belongs together semantically.

    It is probably more interesting to think about whether you can eliminate some of the code by refactoring. For example, if you often use a particular combination of checks with slightly different variables, it might help to outsource the combination of checks into a function and call it wherever appropriate.
    I remember seeing a project once that was well-written for the most part, but it had a problem of that kind. For example, the code for parsing its configuration file was duplicated like this:

    if (file_exists("configfile")) {
      /* tons of code here */
    } else if (file_exists("/etc/configfile")) {
      /* almost the same code again */
    }
    

    That's an extreme example but you get the idea.

提交回复
热议问题