Skip to content

Commit

Permalink
make rules inherit from abstract falsy
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 5, 2021
1 parent 385af99 commit 56d3211
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 8 additions & 4 deletions rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Strict\NodeFactory\ExactCompareFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
Expand All @@ -20,7 +20,7 @@
*
* @see \Rector\Tests\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector\BooleanInIfConditionRuleFixerRectorTest
*/
final class BooleanInIfConditionRuleFixerRector extends AbstractRector
final class BooleanInIfConditionRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
{
public function __construct(
private ExactCompareFactory $exactCompareFactory
Expand All @@ -34,7 +34,7 @@ public function getRuleDefinition(): RuleDefinition
'PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule'
);
return new RuleDefinition($errorMessage, [
new CodeSample(
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
final class NegatedString
{
Expand Down Expand Up @@ -62,6 +62,10 @@ public function run(string $name)
}
}
CODE_SAMPLE
,
[
self::TREAT_AS_NON_EMPTY => false,
]
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Ternary;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Strict\NodeFactory\ExactCompareFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
Expand All @@ -20,7 +20,7 @@
*
* @see \Rector\Tests\Strict\Rector\Ternary\BooleanInTernaryOperatorRuleFixerRector\BooleanInTernaryOperatorRuleFixerRectorTest
*/
final class BooleanInTernaryOperatorRuleFixerRector extends AbstractRector
final class BooleanInTernaryOperatorRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
{
public function __construct(
private ExactCompareFactory $exactCompareFactory
Expand All @@ -34,7 +34,7 @@ public function getRuleDefinition(): RuleDefinition
'PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule'
);
return new RuleDefinition($errorMessage, [
new CodeSample(
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
final class ArrayCompare
{
Expand All @@ -54,6 +54,10 @@ public function run(array $data)
}
}
CODE_SAMPLE
,
[
self::TREAT_AS_NON_EMPTY => false,
]
),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Strict\NodeFactory\ExactCompareFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
Expand All @@ -20,7 +20,7 @@
*
* @see \Rector\Tests\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector\DisallowedShortTernaryRuleFixerRectorTest
*/
final class DisallowedShortTernaryRuleFixerRector extends AbstractRector
final class DisallowedShortTernaryRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
{
public function __construct(
private ExactCompareFactory $exactCompareFactory,
Expand All @@ -34,7 +34,7 @@ public function getRuleDefinition(): RuleDefinition
'PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule'
);
return new RuleDefinition($errorMessage, [
new CodeSample(
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
final class ShortTernaryArray
{
Expand All @@ -54,6 +54,10 @@ public function run(array $array)
}
}
CODE_SAMPLE
,
[
self::TREAT_AS_NON_EMPTY => false,
]
),
]);
}
Expand Down

0 comments on commit 56d3211

Please sign in to comment.