Question: How can I make use of the stats? #175
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
That's acutally a very good question. I think the output stats provides should not be taken too seriously. Meaning it shouldn't dictate how you write your code.
Saying that a project has "good code" based on the average number of methods per class is probably not the best approach. For me personally, good codes is:
But that's how I see what good code is. Everyone is different and has other standards (DRY, SOLID just to mentiond a few). Regarding to Here are two examples of the Output of a smaller app+----------------------------+---------+---------+---------------+-------+------+-------------+
| Name | Classes | Methods | Methods/Class | LoC | LLoC | LLoC/Method |
+----------------------------+---------+---------+---------------+-------+------+-------------+
| Commands | 8 | 33 | 4.13 | 831 | 157 | 4.76 |
| ❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙ | 5 | 60 | 12 | 1194 | 61 | 1.02 |
| ❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙❙ | 60 | 360 | 6 | 2837 | 360 | 1 |
| Controllers | 14 | 21 | 1.5 | 567 | 76 | 3.62 |
| Jobs | 3 | 12 | 4 | 304 | 57 | 4.75 |
| Middlewares | 9 | 5 | 0.56 | 214 | 26 | 5.2 |
| Migrations | 16 | 32 | 2 | 733 | 234 | 7.31 |
| Models | 10 | 6 | 0.6 | 257 | 31 | 5.17 |
| Query Objects | 4 | 8 | 2 | 184 | 21 | 2.63 |
| Requests | 6 | 12 | 2 | 255 | 12 | 1 |
| Resources | 6 | 8 | 1.33 | 192 | 12 | 1.5 |
| Rules | 2 | 8 | 4 | 128 | 24 | 3 |
| Seeders | 6 | 6 | 1 | 131 | 13 | 2.17 |
| Service Providers | 6 | 10 | 1.67 | 198 | 13 | 1.3 |
| PHPUnit Tests | 30 | 111 | 3.7 | 4082 | 738 | 6.65 |
| Other | 35 | 127 | 3.63 | 1774 | 250 | 1.97 |
+----------------------------+---------+---------+---------------+-------+------+-------------+
| Total | 220 | 819 | 3.72 | 13881 | 2085 | 2.55 |
+----------- Code LLoC: 926 • Test LLoC: 738 • Code/Test Ratio: 1:0.8 • Routes: 34 -----------+ The app is fairly small with only 2085 logical lines of code and 34 routes. The code/test ratio is quite good with 0.8. Output of a large app+-------------------+---------+---------+---------------+--------+-------+-------------+
| Name | Classes | Methods | Methods/Class | LoC | LLoC | LLoC/Method |
+-------------------+---------+---------+---------------+--------+-------+-------------+
| Commands | 55 | 115 | 2.09 | 3143 | 724 | 6.3 |
| Controllers | 144 | 339 | 2.35 | 7527 | 2308 | 6.81 |
| Event Listeners | 17 | 37 | 2.18 | 698 | 140 | 3.78 |
| Events | 15 | 15 | 1 | 382 | 113 | 7.53 |
| Jobs | 43 | 129 | 3 | 3144 | 948 | 7.35 |
| Mails | 21 | 48 | 2.29 | 986 | 239 | 4.98 |
| Middlewares | 14 | 9 | 0.64 | 386 | 72 | 8 |
| Migrations | 211 | 420 | 1.99 | 9523 | 3309 | 7.88 |
| Models | 93 | 424 | 4.56 | 6700 | 1313 | 3.1 |
| Notifications | 11 | 43 | 3.91 | 768 | 133 | 3.09 |
| Nova Actions | 1 | 2 | 2 | 70 | 25 | 12.5 |
| Nova Filters | 2 | 4 | 2 | 77 | 10 | 2.5 |
| Nova Resources | 21 | 108 | 5.14 | 2153 | 294 | 2.72 |
| Policies | 18 | 104 | 5.78 | 1568 | 220 | 2.12 |
| Requests | 29 | 79 | 2.72 | 1654 | 188 | 2.38 |
| Resources | 34 | 90 | 2.65 | 1987 | 363 | 4.03 |
| Rules | 3 | 10 | 3.33 | 211 | 68 | 6.8 |
| Seeders | 16 | 17 | 1.06 | 4509 | 342 | 20.12 |
| Service Providers | 9 | 28 | 3.11 | 664 | 185 | 6.61 |
| PHPUnit Tests | 301 | 1603 | 5.33 | 43569 | 13290 | 8.29 |
| Other | 174 | 875 | 5.03 | 11389 | 2951 | 3.37 |
+-------------------+---------+---------+---------------+--------+-------+-------------+
| Total | 1232 | 4499 | 3.65 | 101108 | 27235 | 6.05 |
+------ Code LLoC: 13616 • Test LLoC: 13290 • Code/Test Ratio: 1:1 • Routes: 364 ------+ This app is a bit bigger with 27235 logical lines of code and over 350 routes. We have a code/test ratio of 1:1 which indicates to me, that we have written roughly the same amount of application code as test code. Knowing the app, I know that our tests are quite long/big as we have to do a lot of world building in it. It's definitely time for a refactoring. To answer your questions:
No, I wouldn't use the output of stats to indicate code quality.
Yes. If, for example, you see that the average number of lines of code per method is over 20 I would digg deeper and want to see which classes have methods which are so long. (using the
I would say a good stat is approaching a code/test ratio of 1:1.
I couldn't think of any 😅 |
Beta Was this translation helpful? Give feedback.
-
Thank you @stefanzweifel for giving such a detailed answer ❤️ I definitely need to write more tests! 😆 |
Beta Was this translation helpful? Give feedback.
That's acutally a very good question.
I think the output stats provides should not be taken too seriously. Meaning it shouldn't dictate how you write your code.
laravel-stats
is basically a port ofrake stats
from Ruby On Rails. I've got inspired by this tweet as I thought it would be great to see, how many lines of code I've written for each component.So it's basically just a dashboard which tells you, how many Controller classes you have and how the ratio between methods per class and lines of code per class.
Saying that a project has "good code" based on the average number of methods per class is probably not the best approach.
For me personally, good codes is: