Skip to content
Open
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
17 changes: 14 additions & 3 deletions src/Rules/Deprecations/FetchingDeprecatedConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,27 @@

$constantReflection = $this->reflectionProvider->getConstant($node->name, $scope);

if ($constantReflection->isDeprecated()->yes()) {
if (!$constantReflection->isDeprecated()->yes()) {

Check warning on line 46 in src/Rules/Deprecations/FetchingDeprecatedConstRule.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $constantReflection = $this->reflectionProvider->getConstant($node->name, $scope); - if (!$constantReflection->isDeprecated()->yes()) { + if ($constantReflection->isDeprecated()->no()) { return []; }

Check warning on line 46 in src/Rules/Deprecations/FetchingDeprecatedConstRule.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $constantReflection = $this->reflectionProvider->getConstant($node->name, $scope); - if (!$constantReflection->isDeprecated()->yes()) { + if ($constantReflection->isDeprecated()->no()) { return []; }
return [];
}

$description = $constantReflection->getDeprecatedDescription();
if ($description === null) {
return [
RuleErrorBuilder::message(sprintf(
$constantReflection->getDeprecatedDescription() ?? 'Use of constant %s is deprecated.',
'Use of constant %s is deprecated.',
$constantReflection->getName(),
))->identifier('constant.deprecated')->build(),
];
}

return [];
return [
RuleErrorBuilder::message(sprintf(
"Use of constant %s is deprecated:\n%s",
$constantReflection->getName(),
$description,
))->identifier('constant.deprecated')->build(),
];
}

}
18 changes: 18 additions & 0 deletions tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ public function testFetchingDeprecatedConst(): void
);
}

public function testFetchingDeprecatedConstWithDescription(): void
{
require_once __DIR__ . '/data/fetching-deprecated-const-with-description-definition.php';
$this->analyse(
[__DIR__ . '/data/fetching-deprecated-const-with-description.php'],
[
[
"Use of constant FetchingDeprecatedConstWithDescription\\DEPRECATED_WITH_DESCRIPTION is deprecated:\nin 1.2.0 and is removed from 2.0.0. Use SomeClass::NEW_ONE instead.",
5,
],
[
"Use of constant FetchingDeprecatedConstWithDescription\\DEPRECATED_WITH_DESCRIPTION is deprecated:\nin 1.2.0 and is removed from 2.0.0. Use SomeClass::NEW_ONE instead.",
6,
],
],
);
}

public function testEstrictWithVersionGuard(): void
{
$errors = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace FetchingDeprecatedConstWithDescription;

/**
* @deprecated in 1.2.0 and is removed from 2.0.0. Use SomeClass::NEW_ONE instead.
*/
const DEPRECATED_WITH_DESCRIPTION = 'foo';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

namespace FetchingDeprecatedConstWithDescription;

DEPRECATED_WITH_DESCRIPTION;
\FetchingDeprecatedConstWithDescription\DEPRECATED_WITH_DESCRIPTION;
Loading