Skip to content

Add failing fixture for a parent class that is not first in its file - #292

Open
SanderMuller wants to merge 1 commit into
symplify:mainfrom
SanderMuller:failing-fixture-parent-after-another-class-like
Open

SanderMuller wants to merge 1 commit into
symplify:mainfrom
SanderMuller:failing-fixture-parent-after-another-class-like

Conversation

@SanderMuller

Copy link
Copy Markdown

Failing fixture only, no fix. Follow-up to #282.

SkipParentMethodWithReferenceAfterException is a copy of the existing SkipParentMethodWithReference. The only difference is that its parent sits in a file where another class-like is declared first:

final class SomeExceptionBeforeParentClass extends Exception
{
}

abstract class AbstractSomeParentClassAfterException
{
    public function someMethod(&$useIt)
    {
    }
}

The child gets Use explicit return value over magic &reference, even though the parent enforces the reference. Move the exception below the abstract class and the suite is green again, so declaration order is the only variable.

On the vendor point: the rule does analyse only code I own. The test analyses one file, the fixture. The Source/ file is never in the analysed paths. ReflectionParser::parseMethodReflection() still opens it to find the parent method, and reads findFirstInstanceOf($stmts, ClassLike::class), which is the exception. So the file being read is not the file being analysed, and I don't control it when the parent comes from a dependency.

Bundling an exception with its class is common in older packages, for example iamcal/sql-parser.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant