0 new lines of code at the very first scan of a project

Hi,

We are a SonarCloud customers and successfully used on more that 300 repos. Today we scanned (in an Azure DevOps pipeline) a feature branch of repo (php code) for the very first time and we got a 0 line of code scanned. We also tried to add a brand new file (“test.php” with a couple of php lines of code) but, while the file actually appeared in the Sonar code browser, the status again reported “0 new lines of code”.

It’s the first time that we experience such a behavior…

Any clue?


Hey there.

I’m guessing your code isn’t parsing at all and therefore no lines of code are reported… your PHP example isn’t exactly syntactically correct :smiley: It misses a closing tag.

<?php
echo "un due tre"
?>

Hi Colin,

as I’ve been told by my developer, the closing tag is optional (and somehow discouraged by the best practices of the language) for pure-PHP files. Moreover we have tons of other php-based projects that never suffered of this issue. Anyway, I tried to add the closing tag but with no benefits.

In the code browser, I see this:

image

and this in the file details.

In attachment the scanner log where I don’t see any evident reason for the behavior.

log_scanner.txt (18.8 KB)

Thanks,
Andrea

Hello @Andrea_Migliaccio,

You are right, the closing tag at the end is optional. However, in your first code example, the semicolon was missing, so a parser error probably occurred. The logs show that 44 PHP files were scanned without a parser error. So everything looks good here.

The fact that there is a 0 in “new code smell” does not mean that no lines of code were scanned. It means that no active rule has found a code smell, bug or other issue in these files. In your second screenshot you can also see that 5 lines were recognized and one of them is correctly present as a line not covered by a test. Maybe check your settings again to make sure that all the rules you want to apply to PHP are activated.

Cheers,
Nils

Hi @Nils_Werner ,

the problem is not that we have “0 new code smell” (that may also be a fortunate case) but we have 0 of everything and specifically, 0 line of codes that is definitively wrong :slight_smile:

Andrea

Just a hint, as I can’t help with PHP much:
On .NET side, this is usually caused when project is classified as a TEST code.
I’m not sure how this works in PHP plugin. Verbose log might help.

Hi @Pavel_Mikula , actually we had a similar issue with a .net project and in that case, as you mentioned, this was caused by a “xunit” dependency that categorized the project as test, thus, not scanned. I was able to find as clearly described in the SonarScanner for .net documentation (SonarScanner for .NET | SonarQube Docs)

We were not able to find a seemingly clear documentation of the php scanner… We actually have phpunit as dev-dependency but this should be quite common. Any chance to have a feedback from the sonar-php maintainer? BTW, I’m taking a look at the sonar-php source code on github an try to figure it out…

@Pavel_Mikula @Nils_Werner We haven’t figured it out yet. I made some run with the loglevel=DEBUG and different scenarios:

  • If we run a pipeline that simply “download the git repo and scan it” everything works fine
  • if we run a pipeline that “download the git repo, execute a composer install to download dependencies” we face the issue.
    One possibile cause is that the “composer install” leverage one its features and download some dependencies from other git repos. My guess is that the scanner somehow get confused tracking the changes at git level and doesn’t correctly scan the file content…

Hi @Andrea_Migliaccio ,

Could you please give us the debug logs from a scan that report 0 lines, for us to analyze?

1 Like