Roave / BetterReflection

:crystal_ball: Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.
MIT License
1.18k stars 131 forks source link

Kill startLine & endLine mutants #1407

Closed staabm closed 6 months ago

staabm commented 6 months ago

lets see how https://github.com/nikic/PHP-Parser/pull/985 affects mutations

refs https://github.com/Roave/BetterReflection/issues/1382

staabm commented 6 months ago

@kukulich it looks like it doesn't improve mutations. I guess phpdoc-types are not useful for that (and only native types are taken into account?)

Ocramius commented 6 months ago

Phpdoc types are considered: need to likely checked in more depth 🤔

Thanks for trying though!

kukulich commented 6 months ago

@staabm

I think this can work:

$startLine = $node->getStartLine()
if ($startLine !== -1) {
    $this->startLine = $startLine;
}

No assert -> no mutation and no mutant :) Psalm/Phpstan should be happy too thanks to your change in PhpParser.

The current solution probably does not work because if ($node->hasAttribute('startLine')) { does not tell Psalm that $node->getStartLine() is only positive-int. That's why the assert is not reported by Psalm as useless.

staabm commented 6 months ago

Thank you. I will give your idea a try tomorrow

(Btw: the php-parser PR was merged)

staabm commented 6 months ago

the psalm error is a bug, reported in https://github.com/vimeo/psalm/issues/10826

kukulich commented 6 months ago

It looks it's very complicated to kill one mutant 😄

staabm commented 6 months ago

It looks it's very complicated to kill one mutant 😄

hehe - agree, its a lot of change. but I feel the code is easier to read after the PR.

kukulich commented 6 months ago

I feel the code is easier to read after the PR.

I agree :)

staabm commented 6 months ago

@Ocramius mutants will be killed on the next php-parser release. I think its good to go.

Ocramius commented 6 months ago

Thanks @staabm!

Ocramius commented 6 months ago

Btw: notice the reduction in mutations: that really says a lot whenever we refactor :)