Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 lines of code in this file so far.

Is it better practice to include a separate file if a statement is true; or simply type the code directly in the if statement itself?

Is their a maximum number of lines of code for a single file that should be adhered to with PHP?

like image 338
Marcus Avatar asked Dec 28 '09 02:12

Marcus


1 Answers

You may want to read a book like Clean Code by Bob Martin. Here are a few nuggets from that book:

  • A class should have one responsibility
  • A function should do one thing and do it well

With PHP, if you aren't using the Class approach; you're going to run into duplication problems. Do yourself a favor and do some reading on the subject; it'll save you a lot more time in extending and maintenance.

like image 91
George Stocker Avatar answered Nov 15 '22 18:11

George Stocker