Skip to content

Released: StructArmed 0.19.0

Choose a tag to compare

@samsonasik samsonasik released this 08 Oct 05:58
· 15 commits to main since this release
0.19.0
e63a143

ci build PHPStan

StructArmed 0.19.0 introduces configurable project base paths and a new architecture rule for restricting constant usage.

This release introduces:

  • --basepath and its -d alias for analysing projects from a separate working directory;
  • the new MayNotUseConstantRule for restricting constant usage within architecture layers;
  • additional DDD preset restrictions for STDIN, STDOUT, and STDERR;
  • dependency update and internal cleanup.

Configurable Project Base Path

StructArmed now supports specifying the project root through --basepath or its short alias -d.

This is useful when StructArmed is installed in a separate tools directory instead of the project's root directory.

For example:

composer.json
src/
tests/
tools/
└── structarmed/
    ├── composer.json
    ├── structarmed.php
    └── vendor/

From tools/structarmed, run:

vendor/bin/structarmed analyse --basepath=../../

Or use the shorter form:

vendor/bin/structarmed analyse -d ../../

The specified base path is used for resolving:

  • architecture layer paths;
  • scan paths;
  • the project's composer.json and PSR-4 mappings;
  • cache directories;
  • baseline paths.

Configuration discovery checks the current working directory first, followed by the specified base path. An explicit --config remains relative to the current working directory.

The option also works with cache clearing:

vendor/bin/structarmed --basepath=../../ --clear-cache

CLI options may be specified before or after the command.

This makes StructArmed easier to integrate into projects that keep development tools and their dependencies separate from the application.

New MayNotUseConstantRule

StructArmed introduces:

MayNotUseConstantRule

This rule prevents classes, traits, and enums in a specified architecture layer from using a forbidden constant.

For example:

use Boundwize\StructArmed\Rule\Rules\Usage\MayNotUseConstantRule;

->rule(
    'domain_no_php_eol',
    new MayNotUseConstantRule(
        layer: 'Domain',
        constant: 'PHP_EOL',
    ),
)

The rule supports global and namespaced constants:

new MayNotUseConstantRule(
    layer: 'Domain',
    constant: 'Vendor\\Config\\DEBUG',
)

Constant names are matched case-sensitively, while namespace names are matched case-insensitively.

The rule also handles PHP's runtime fallback behavior for unqualified constants inside namespaces.

DDD Preset Improvements

The DDD preset now prevents the Domain layer from directly using these constants:

  • STDIN
  • STDOUT
  • STDERR

These restrictions are enabled automatically through:

Preset::DDD()

This helps keep domain logic independent of direct console input and output.

Internal Improvements

  • Remove unused RuleViolationCollection::forLayer() and toJson() methods.
  • Update fidry/cpu-core-counter dependency to ^1.4.
  • Update the analysis cache format to accommodate constant usage information.
  • Temporarily exclude PHP 8.5 on macOS from CI due to runner setup issues.

What's Changed

  • Add MayNotUseConstantRule and DDD preset restrictions in #495.
  • Add configurable project base paths using --basepath and -d in #496.
  • Improve configuration discovery across working and project directories in #496.
  • Remove unused RuleViolationCollection::forLayer() and toJson() methods in #476.
  • Update fidry/cpu-core-counter to ^1.4 in #490.

Full Changelog: 0.18.11...0.19.0