Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Line count calculation bug causes detection misses #43

Closed
dotdash opened this Issue Jul 25, 2012 · 1 comment

Comments

Projects
None yet
3 participants

dotdash commented Jul 25, 2012

Using the default settings for min-lines and min-tokens, the following two blocks aren't detected as duplicates, although they meet both requirements.

<?php
function dupeA() {
    for ($i = 0; $i < 10; $i++) {
        echo 123, 123, 123, 123, 123, 123, 123, 123;
        echo 124, 123, 123, 123, 123, 123, 123, 123;
        echo 125, 123, 123, 123, 123, 123, 123, 123;
        echo 126, 123, 123, 123, 123, 123, 123, 123;
        echo 127, 123, 123, 123, 123, 123, 123, 123;
        echo 128, 123, 123, 123, 123, 123, 123, 123;
        echo 129, 123, 123, 123, 123, 123, 123, 123;
    }
}

function dupeB() {
    for ($i = 0; $i < 10; $i++) {
        echo 123, 123, 123, 123, 123, 123, 123, 123;
        echo 124, 123, 123, 123, 123, 123, 123, 123;
        echo 125, 123, 123, 123, 123, 123, 123, 123;
        echo 126, 123, 123, 123, 123, 123, 123, 123;
        echo 127, 123, 123, 123, 123, 123, 123, 123;
        echo 128, 123, 123, 123, 123, 123, 123, 123;
        echo 129, 123, 123, 123, 123, 123, 123, 123;
    }
}

The reason for this is in the default detector strategy, which only looks at the starting line for the set of tokens it currently checks. But of course the required 70 tokens are spread across multiple lines, so instead of only looking for the line of the first token in this block, you also have to check the last one.

A somewhat crude fix is here: https://gist.github.com/3176121

Contributor

aboks commented May 24, 2013

This issue is also fixed by #65 and can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment