pdepend/pdepend

Values of hnd and hnt are mixed up in XML report

andrey-tech opened this issue · 1 comments

  • PHP Depend version: 2.14.0
  • PHP Version: 7.4.33
  • Installation type: composer
  • Operating System / Distribution & Version: GNU/Linux Ubuntu 5.15.0-83-generic x86_64

Current Behavior

Values of Halstead Vocabulary (hnd) and Halstead Length (hnt) for methods are mixed up in XML report.

Expected Behavior

Values of Halstead Vocabulary (hnd) and Halstead Length (hnt) for methods are correct in XML report.

Steps To Reproduce:

For trivial method x() of class Test:

class Test
{
    function x()
    {
        return 1 + 1;
    }
}

pdepends returns in XML-report: Halstead Vocabulary hnd=6 and Halstead Length hnt=5.

This is incorrect, because obviously for method x():

  • Halstead Vocabulary (the total number of unique operator and unique operand occurrences) = 5
  • Halstead Length (the total number of operator occurrences and the total number of operand occurrences) = 6
<method name="x" start="7" end="10" ccn="1" ccn2="1" loc="4" cloc="0" eloc="3" lloc="1" ncloc="4" npath="1" hnt="5" hnd="6" hv="12.924812503606" hd="4" hl="0.25" he="51.699250014423" ht="2.8721805563568" hb="0.0046259568124894" hi="3.2312031259014" mi="81.675383960131"/>

Please check and fix.

Checks before submitting

  • [✓] Be sure that there isn't already an issue about this. See: Issues list
  • [✓] Be sure that there isn't already a pull request about this. See: Pull requests
  • [✓] I have added every step to reproduce the bug.
  • [✓] If possible I added relevant code examples.
  • [✓] This issue is about 1 bug and nothing more.
  • [✓] The issue has a descriptive title. For example: "Default value is not available in AST when it's an array".

Hello, indeed hnd <= hnt should always be true the issue came from invalid calculation for n1, n2, N1 and N2.

This had been fixed in https://github.com/pdepend/pdepend/pull/669/files#diff-ebf84988be0dd6fc20e9c21bb87f5624f31ac61b61c6ac1ad44bac45a7e954ce and it will be released in 2.15.0.

You can already test it with composer require "pdepend/pdepend:dev-master as 2.15.0"