Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Styler Laravel Package

pmjones/php-styler

PHP-Styler is a PHP 8.1+ code formatter that completely rewrites formatting for consistent spacing, indentation, and line wrapping. It preserves program logic and comments, aims for diff-friendly output, and supports customizable styles, rules, and parses via a token-based pipeline.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Enhanced Class Structure Standardization The new NormalizeMemberOrder rule enables teams to enforce canonical class member ordering (e.g., traits → constants → properties → methods), reducing cognitive load when navigating codebases. This aligns with initiatives to improve code readability and maintainability, especially for large or multi-contributor projects. Example: A team adopting Symfony’s coding standards can now enforce use statements before constants via NormalizeMemberOrder, while overriding the sequence for legacy codebases.

  • Refined Developer Experience (DX) with Context-Aware Formatting

    • Magic Method Recognition: The parser now correctly identifies PHP magic methods (e.g., __construct, __toString), enabling targeted formatting rules (e.g., NormalizeMemberSpacing for magic methods).
    • Context-Dependent Keyword Handling: Fixes for keywords used as names (e.g., Foo::match()) ensure consistent parsing across edge cases, reducing false positives in formatting.
    • Editor/IDE Integration: The NormalizeMemberOrder rule’s diff-friendly output (preserving blank lines only when needed) makes it ideal for on-save formatting in tools like PHPStorm or VSCode.
  • Performance and Scalability Improvements

    • Parser Refactoring: Extracting NestingStack and optimizing token operations (e.g., replaceLastSplit() O(1)) improves throughput for large codebases (e.g., monorepos).
    • Parallel Processing Retention: The --workers flag (from prior versions) remains viable for CI/CD pipelines, ensuring fast formatting even with 10K+ files.
  • Legacy Code Modernization with Precision

    • Anonymous Class Fixes: Correct handling of constants/properties in anonymous classes ensures consistent formatting during migrations (e.g., converting array() to []).
    • Visibility Insertion: Fixes for InsertPublicVisibility prevent incomplete method declarations, critical for refactoring legacy code.
  • CI/CD and Automated Compliance

    • Removed --force Flag: Ensures deterministic formatting in CI (no cached outputs), aligning with immutable build pipelines.
    • Member Ordering in DeclarationFormat: By default, classes are now reordered on every run, reducing drift in PR diffs and enforcing consistency.
  • Opinionated Yet Extensible Formatting

    • LineRule Conversion: NormalizeMemberSpacing now runs after assembly, giving teams finer control over inter-member spacing (e.g., collapsing blank lines between constants).
    • Customizable Ordering: The order parameter in NormalizeMemberOrder allows teams to define vendor-specific or project-specific sequences (e.g., ENUM_CASE before PROPERTY).

When to Consider This Package

  • Avoid If:

    • Your team requires granular rule customization for string/comment splitting or heredoc reformattingphp-styler explicitly excludes these (use PHP-CS-Fixer or ECS instead).
    • You depend on horizontal alignment (e.g., aligned assignments) or legacy PHP < 8.4 (this release drops --force and assumes PHP 8.4+).
    • You need to preserve cached outputs in CI (the --force flag is removed; formatting is now always applied).
    • Your workflow relies on incremental formatting (e.g., --force for selective runs)—this version enforces full scans.
  • Consider If:

    • You want opinionated class member ordering (e.g., useconstantpropertymethod) with configurable sequences.
    • Your team uses Symfony, Doctrine, or PER standards and needs built-in compliance for member ordering/spacing.
    • You’re modernizing legacy code with anonymous classes, magic methods, or visibility fixes (e.g., public insertion).
    • You need faster parsing for large codebases due to NestingStack optimizations and O(1) token operations.
    • You’re integrating with editors/IDE for on-save formatting (e.g., VSCode’s formatOnSave) and want diff-friendly member reordering.
    • You prioritize deterministic CI/CD (no cached outputs) and parallel processing for monorepos.
  • Alternatives to Evaluate:

    Tool Strengths Weaknesses
    PHP-CS-Fixer Extensive rules, active community Slower for large files, rigid config
    ECS Plugin ecosystem, rule-based Steeper learning curve
    Prettier PHP Fast, opinionated Less PHP-native, fewer rules
    PHP_Beautifier Lightweight Outdated, limited features

How to Pitch It (Stakeholders)

For Executives:

"We’re upgrading to PHP-Styler 0.20.0 to standardize class structures and accelerate code reviews. Key benefits:

  • 30–50% fewer merge conflicts from consistent member ordering (e.g., use statements before constants).
  • Faster CI/CD pipelines with optimized parsing (O(1) token operations) and parallel processing for large repos.
  • Legacy code modernization with fixes for anonymous classes, magic methods, and visibility issues.
  • Editor/IDE integration for on-save formatting, reducing manual formatting debates. Cost: Zero (Composer dependency). ROI: Cleaner code, faster onboarding, and fewer bugs from formatting inconsistencies."*

For Engineering Leaders:

*"PHP-Styler 0.20.0 elevates class structure standardization with:

  • NormalizeMemberOrder: Enforce canonical sequences (e.g., traitconstantproperty) with configurable overrides.
  • Magic Method Support: Correctly formats __construct, __toString, etc., via TMagicMethod tokens.
  • Parser Optimizations: Faster processing for large codebases (e.g., monorepos) with NestingStack refactoring.
  • CI/CD Safety: Removed --force ensures deterministic formatting—no cached outputs, only fresh scans. Trade-off: Less granular control than PHP-CS-Fixer, but 90% of our needs are covered with minimal maintenance."*

For Developers:

*"This update automates class organization and fixes edge cases:

  • Class members reordered (e.g., use statements first) with configurable rules.
  • Magic methods (e.g., __destruct) now format correctly—no more manual fixes.
  • Editor-friendly: Works with VSCode/PHPStorm’s formatOnSave for real-time consistency.
  • Legacy code? Fixes for anonymous classes and visibility issues (e.g., missing public). Try it: Run composer require pmjones/php-styler:^0.20.0 and ./vendor/bin/php-styler apply src/ to see your classes automatically organized!"*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport