I just discovered the official Symfony best practices about controllers, where it is written:
As a rule of thumb, you should follow the 5-10-20 rule, where controllers should only define 5 variables or less, contain 10 actions or less and include 20 lines of code or less in each action.
I have a question about its meaning, as it could be understood in two different ways.
"controllers" designates the controller classes (ex
class MyController{}
) & "actions" designates the controller functions (expublic function indexAction(){}
) => It makes no sense to me"controllers" designates the controller functions (ex
public function indexAction(){}
) & "actions" designates instructions in these functions (exif(){//do something}
) => It makes sense to me
In case 1, that means something like:
// Approximate maximum number of lines : 200
class MyController {
// Max 20 lines of code
public function firstAction(){}
[...]
// Max 20 lines of code
public function tenthAction(){}
}
Also, I can't get in this case what means "5 variables or less". 5 global variables? 5 local variables for all of the 10 Actions?
In case 2, that means something like:
// No maximum number of lines
class MyController {
// Max 10 actions * 20 lines by actions = 200 lines of code, and 5 local variables
public function firstAction(){}
[...]
// Max 10 actions * 20 lines by actions = 200 lines of code, and 5 local variables
public function fiftiethAction(){}
}
The goal of my question is to be absolutely sure to understand the good meaning. But I also think that it would be useful to ask the Symfony team to rewrite this sentence without leaving any ambiguities? I specially think about non-English developers like I am, or Symfony beginners.
Considering that the case 2 is the good one, the word "action(s)" could be replaced with "instruction(s)" or "directive(s)", for example?