sebastianbergmann / phploc

A tool for quickly measuring the size of a PHP project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why is the directory count subtracted by 1?

TiEul opened this issue · comments

commented

Hey,

I noticed that the directory count of phploc seems to be off by 1 and after a quick look at the source files I found the following line:

https://github.com/sebastianbergmann/phploc/blob/master/src/Publisher.php#L23

public function getDirectories()
{
    return $this->getCount('directories') - 1;
}

I am actually wondering why this is done as I am sure I am simply missing the intention of this. However, it seems to result in the wrong value being reported, at least in my case. This can easily be reproduced, just create a directory with X subdirectories, each of them containing a valid PHP file. PHPLoc will report X - 1 directories.

/some/directory/subdirectory01/test.php
/some/directory/subdirectory02/test.php
/some/directory/subdirectory03/test.php
/some/directory/subdirectory04/test.php
/some/directory/subdirectory05/test.php
/some/directory/subdirectory06/test.php
/some/directory/subdirectory07/test.php

vendor/phploc/phploc/phploc --count-tests /some/directory/

Expected result:

Directories                                          7
Files                                                7

Actual Result:

Directories                                          6
Files                                                7

That is not happening with me. I am using the latest version.

commented

Hey @tonylds1, thanks for helping out and providing some input. I just tried it again and I also followed PHPLOC's logic with xDebug and it definitely counts the directories correctly and will then mistakenly subtract one at the end when getDirectories() is called, as I had already explained above.

Here's an even more specific way of reproducing this, including all relevant software versions and steps I have taken to cause this problem:

tim@tim-VirtualBox ~ $ vendor/phploc/phploc/phploc --version
phploc 4.0.0 by Sebastian Bergmann.

tim@tim-VirtualBox ~ $ mkdir ~/phploctest/
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test01
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test02
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test03
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test04
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test05
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test06
tim@tim-VirtualBox ~ $ mkdir ~/phploctest/test07
tim@tim-VirtualBox ~ $ touch ~/phploctest/test07/test.php
tim@tim-VirtualBox ~ $ touch ~/phploctest/test06/test.php
tim@tim-VirtualBox ~ $ touch ~/phploctest/test05/test.php
tim@tim-VirtualBox ~ $ touch ~/phploctest/test04/test.php
tim@tim-VirtualBox ~ $ touch ~/phploctest/test03/test.php
tim@tim-VirtualBox ~ $ touch ~/phploctest/test02/test.php
tim@tim-VirtualBox ~ $ touch ~/phploctest/test01/test.php
tim@tim-VirtualBox ~ $ vendor/phploc/phploc/phploc ~/phploctest/
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          6
Files                                                7

[...]

Further information on this particular virtual machine instance:

tim@tim-VirtualBox ~ $ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

tim@tim-VirtualBox ~ $ php --version
PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep  2 2017 05:56:43) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
    with Zend OPcache v7.1.9-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

If you are unable to reproduce it, maybe supply details on your software stack, maybe this is an issue that is limited to the software versions I am using but that would seem very odd.

Hi @TiEul, that is an awesome issue for me, I had not noticed that. In fact, I improve your test and add another folder inside test01 folder and got this:

tony@tony-pc:~$ mkdir phploctest
tony@tony-pc:~$ cd phploctest/
tony@tony-pc:~/phploctest$ mkdir test01
tony@tony-pc:~/phploctest$ mkdir test01/level02
tony@tony-pc:~/phploctest$ mkdir test02
tony@tony-pc:~/phploctest$ mkdir test03
tony@tony-pc:~/phploctest$ mkdir test04
tony@tony-pc:~/phploctest$ mkdir test05
tony@tony-pc:~/phploctest$ mkdir test06
tony@tony-pc:~/phploctest$ mkdir test07
tony@tony-pc:~/phploctest$ echo "some text" >> test07/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test06/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test05/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test04/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test03/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test02/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test01/test.php
tony@tony-pc:~/phploctest$ echo "some text" >>  test01/level02/test.php
tony@tony-pc:~/phploctest$ php ~/lab/phploc/php
phploc 4.0.0-6-g659edc4 by Sebastian Bergmann.

Directories                                          7
Files                                                8

I mean, it goes recursively running all the files and getting its directory.

commented

This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.

commented

This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions.