Tuesday, May 23, 2017

how should remove else blocks

PHPMD is telling me that I should avoid else block in this test, but in those case, I can't find a way to remove them.

Here is the code:

if ($fight->c1 == NULL) {
    if ($fight->c2 == NULL) {
        // C1 and C2 Is Bye
        $this->assertEquals($parentFight->$toUpdate, NULL);
    }
    else {
        // C1 Is Bye
        $this->assertEquals($parentFight->$toUpdate, $fight->c2);
    }
}
else {
    if ($fight->c2 == NULL) {
        // C2 Is Bye
        $this->assertEquals($parentFight->$toUpdate, $fight->c1);
    }
    else {
        // C1 and C2 Are all set
        $this->assertEquals($parentFight->$toUpdate, NULL);
    }
}

Any Idea???



via Juliatzin del Toro

Advertisement