Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test-case covering property referenced via "static" keyword #66

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture;

class LocallyUsedStaticPropertyViaStatic
{
public static $somePublicStaticProperty;

private function run()
{
return static::$somePublicStaticProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use TomasVotruba\UnusedPublic\Rules\UnusedPublicPropertyRule;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\IgnoresPrivateApiProperty;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\LocallyUsedStaticProperty;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\LocallyUsedStaticPropertyViaStatic;
use TomasVotruba\UnusedPublic\Tests\Rules\UnusedPublicPropertyRule\Fixture\LocalyUsedPublicProperty;

final class UnusedPublicPropertyRuleTest extends RuleTestCase
Expand Down Expand Up @@ -51,6 +52,16 @@ public static function provideData(): Iterator
[[$errorMessage, 7, RuleTips::SOLUTION_MESSAGE]],
];

$errorMessage = sprintf(
UnusedPublicPropertyRule::ERROR_MESSAGE,
LocallyUsedStaticPropertyViaStatic::class,
'somePublicStaticProperty'
);
yield [
[__DIR__ . '/Fixture/LocallyUsedStaticPropertyViaStatic.php'],
Copy link
Contributor Author

@staabm staabm Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw: I wondered why we separate test-classes between Fixture and Source in this repo.

it might make sense todo so in a rector package, but I think its not useful in a phpstan rule/extension package?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it can be only /Fixture here, if a file is provided in list of files analysed by PHPStan.

[[$errorMessage, 7, RuleTips::SOLUTION_MESSAGE]],
];

yield [[
__DIR__ . '/Fixture/AnotherClassUsingPublicStaticProperty.php',
__DIR__ . '/Source/SkipExternallyUsedPublicStaticProperty.php',
Expand Down