Skip to content

Released: StructArmed 0.14.0

Choose a tag to compare

@samsonasik samsonasik released this 26 Jun 21:21
0.14.0
4bcc584

ci build PHPStan

StructArmed 0.14.0 introduces new Boundwize\StructArmed\Rule\FixableInterface that when rule implements it, it can apply a fix with make use of fix method, eg:

use Boundwize\StructArmed\Rule\FixableInterface;

-final readonly class SomeRule implements RuleInterface
+final readonly class SomeRule implements RuleInterface, FixableInterface
{
+    public function fix(RuleViolation $ruleViolation): bool
+    {
+          // do custom fix implementation based on RuleViolation object information
+    }
}

This feature brings some example of it that utilize PhpParser:

  • MustDeclareConstantVisibilityRule
  • MustDeclareMethodVisibilityRule
  • MustDeclarePropertyVisibilityRule

that extends Boundwize\StructArmed\Rule\Fixer\PhpParser\AbstractPhpParserFixableRule that we only need to define the PhpParser visitor that do the fix:

protected function createFixerVisitor(RuleViolation $ruleViolation): AddPublicConstantVisibilityVisitor
{
    /** @var string $constantName */
     $constantName = $ruleViolation->constantName;

     return new AddPublicConstantVisibilityVisitor(
           $ruleViolation->className,
           $constantName
      );
}

The usage will be:

vendor/bin/structarmed analyze --fix
Screenshot 2026-06-27 at 04 25 02

The example usage will be on https://boundwize.github.io/structarmed/custom-rules-and-presets/

What's Changed

  • Add FixableInterface to allow --fix on rule that implements it by @samsonasik in #179

Full Changelog: 0.13.8...0.14.0