So typical Yii 2 application has close to or around quarter of million lines of code.
These numbers are excluding vendor folder naturally (so framework files itself any many external libraries). If we would like to include them as well, we would need to add two million lines of code to the above numbers.
I am asking and performing my checks on bare-bone Yii 2 app as taken from the official repository using composer create-project.
Thus, I believe that this isn’t very depended and these numbers will change slightly only during future updates of the repository (given the fact that there will be many updates since you are all focusing on Yii 3).
As written in the introduction, this question was initiated by deciding on which Sonar’s package to purchase. Sonar has one of the packages set at 250k LOC (lines of code) with 500k LOC and 1M LOC following.
Based on the above calculations I can surely assure myself that 250k LOC is not enough, that 500k LOC is a minimum and 1M LOC must be considered. That’s pretty much all that I have expected. Thanks!
What about writing a Python script to do that?
It should be doable and will give accurate information than estimate which depends on actual code being analyzed
Sounds good, although not available to me → I don’t know Python.
It should be doable and will give accurate information than estimate which depends on actual code being analyzed
Depends on what you understand as “accurate information”. This solution (though a bit unhandy) counts the exact number of lines of code in each and every file by counting total number of line delimiters used in all three systems.
Easy to learn or hire someone to do it
Here is a script that breaks lines by semi colon. So counts by semicolon as only criteria. You can expand it to check braces for example if you so wish. You can combine it with directory traversing as well as some fixed ignored paths to get a complete solution
Also you can use Yii2 command controller to accomplish the same. PHP have rich directory traversing functions that you can use.
All the best!
#full Path to file
path = '...'
lineCount = 0
with open(path) as file:
for codeLine in file.read().replace('\n', '').split(';'):
if codeLine.strip():
lineCount +=1
print('++++++++'+str(codeLine))
print("Total Line count is: ", str(lineCount))
Hi Stefano, thanks for your time and for sharing this with me and others. I’ll definitely consider using this.
BTW: Splitting by semicolon is not an option in this scenario. If I ever decide to pay an enormous fee for Sonar, I will expect it to validate security of all my files, including HTML and Javascript, not just PHP code.
These files are split by line delimiter rather than semicolon.
I wonder how can LOC relate to project value.
If I would copy same line 1 million times - will it be 4x more valuable than Yii2 app?
Quality of the code & added value - that’s what matters, not the number of lines.
You can have 50% of remarks in the code, shitty / buggy code … etc
At least, I would recommend some complexity measuring tools - e.g. https://phpmetrics.org/ to check with.
I don’t think that LoC relates to project value. For the reasons that you have outlined and for many more.
I need LoC to purchase an accurate package of Sonar. Differences between packages in terms of price are huge, so I appreciate and consider every method of measuring LoC provided by members here.
I also think that LoC tells you nothing. But, that’s how Sonar builds their business.
One of my project totally 44k LOC. When you are using correctly the framework. Use dependency manager and exclude vendor directory, it is enough for version control…