Skip to content
This repository

Line count calculation bug causes detection misses #43

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

3 participants

Björn Steinbrink Sebastian Bergmann Arnout Boks
Björn Steinbrink

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

Arnout Boks
aboks commented May 24, 2013

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

Sebastian Bergmann sebastianbergmann closed this May 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.