Skip to content
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
Expand Up @@ -22,8 +22,25 @@ public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Flip negated ternary of `instanceof` to direct use of object', [
new CodeSample(
'echo ! $object instanceof Product ? null : $object->getPrice();',
'echo $object instanceof Product ? $object->getPrice() : null;'
<<<'CODE_SAMPLE'
class SomeClass
{
public function resolvePrice(object $object): ?int
{
return ! $object instanceof Product ? null : $object->getPrice();
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function resolvePrice(object $object): ?int
{
return $object instanceof Product ? $object->getPrice() : null;
}
}
CODE_SAMPLE
),
]);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Config/Level/CodeQualityLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\EarlyReturn\Rector\StmtsAwareInterface\ReturnEarlyIfVariableRector;
use Rector\Instanceof_\Rector\Ternary\FlipNegatedTernaryInstanceofRector;
use Rector\Php52\Rector\Property\VarToPublicPropertyRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
Expand Down Expand Up @@ -163,6 +164,7 @@ final class CodeQualityLevel
PreparedValueToEarlyReturnRector::class,
ReturnEarlyIfVariableRector::class,
InlineIsAInstanceOfRector::class,
FlipNegatedTernaryInstanceofRector::class,
InlineConstructorDefaultToPropertyRector::class,
TernaryEmptyArrayArrayDimFetchToCoalesceRector::class,
OptionalParametersAfterRequiredRector::class,
Expand Down
Loading