spaze / phpstan-disallowed-calls

PHPStan rules to detect disallowed method & function calls, constant, namespace, attribute & superglobal usages
MIT License
255 stars 17 forks source link

Fix test class name #260

Closed szepeviktor closed 3 months ago

szepeviktor commented 3 months ago

... so it matched the file name tests/ControlStructures/ForeachControlStructureTest.php

szepeviktor commented 3 months ago

A crude tool.

find -type f -name "[A-Z]*.php" | xargs -I% -- bash -c 'grep -q -m1 "^\(class\|abstract class\|final class\|interface\)\? $(basename -s .php %)" "%" || echo "Classname not found: %"'
spaze commented 3 months ago

Nice catch, thanks! I think phpcs may be able to find it as well, of configured, possibly using this rule. I'll look into it. [Update: couldn't get this rule to work, nevermind]

spaze commented 3 months ago

Thanks! (Introduced in #257 by not fully removing the original class name from the copy/pasted file)

szepeviktor commented 3 months ago

Glad to contribute.

For PSR-4 there is composer dump-autoload --dev --optimize --strict-psr

spaze commented 3 months ago

For PSR-4 there is composer dump-autoload --dev --optimize --strict-psr

Cool, though it doesn't seem to detect the case fixed here:

$ composer dump-autoload --dev --optimize --strict-psr
Generating optimized autoload files
Generated optimized autoload files containing 1920 classes
$ echo $?
0
$ grep extends ./tests/ControlStructures/ForeachControlStructureTest.php
class WhilForeachControlStructureTest extends RuleTestCase
szepeviktor commented 3 months ago

it doesn't seem to detect the case fixed here:

Of course! Tests are not PSR-4 but "classmap".

spaze commented 3 months ago

Ah sorry, I see now what you mean. I thought the "For PSR-4 ..." comment was somehow related to this issue. Turns out, it wasn't, or at least not directly :-)