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

Coding Standard Laravel Package

sunrise/coding-standard

Sunrise PHP Coding Standard provides a ready-to-use PHPCS ruleset (ruleset.xml) you can reference in your project to enforce consistent code style across src and tests, aligned with PSR-1 and PSR-2.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require --dev sunrise/coding-standard
    

    Add the package to your project's require-dev dependencies.

  2. Configure PHPCS Create a phpcs.xml (or phpcs.xml.dist) in your project root:

    <?xml version="1.0"?>
    <ruleset name="Project Coding Standard">
        <rule ref="./vendor/sunrise/coding-standard/ruleset.xml"/>
        <file>src</file>
        <file>tests</file>
    </ruleset>
    
  3. First Run Validate your codebase:

    vendor/bin/phpcs --standard=./phpcs.xml src tests
    

First Use Case

  • Pre-commit Hook: Integrate with Git hooks to enforce standards before commits. Example (.git/hooks/pre-commit):
    #!/bin/sh
    vendor/bin/phpcs --standard=./phpcs.xml $1
    

Implementation Patterns

Workflows

  1. Team Onboarding

    • Share phpcs.xml in your team’s repo.
    • Use phpcbf (built-in) for auto-fixing:
      vendor/bin/phpcbf --standard=./phpcs.xml src
      
  2. CI/CD Integration

    • Fail builds on violations (e.g., GitHub Actions):
      - name: Run PHPCS
        run: vendor/bin/phpcs --standard=./phpcs.xml --warning-severity=3 src
      
  3. Custom Rulesets

    • Extend the Sunrise ruleset by overriding specific rules:
      <ruleset>
          <rule ref="./vendor/sunrise/coding-standard/ruleset.xml"/>
          <rule ref="PSR2" />
          <rule ref="Generic.Files.LineEndings" />
          <exclude name="Generic.Files.LineEndings" from="tests/*" />
      </ruleset>
      

Integration Tips

  • IDE Support: Configure PHPStorm/VSCode to use phpcs.xml for real-time feedback.
  • Parallel Execution: Use parallel flag for large codebases:
    vendor/bin/phpcs --standard=./phpcs.xml --parallel=8 src
    
  • Custom Error Formatting: Pipe output to tools like slack-notify for alerts.

Gotchas and Tips

Pitfalls

  1. Outdated Ruleset

    • The package hasn’t been updated since 2019. Verify compatibility with PHP 8.x/PSR-12 (if needed).
    • Workaround: Combine with squizlabs/php_codesniffer for modern rules:
      <rule ref="vendor/sunrise/coding-standard/ruleset.xml"/>
      <rule ref="PSR12"/>
      
  2. False Positives

    • Sunrise’s rules may conflict with Laravel conventions (e.g., use App; vs. use App\).
    • Fix: Exclude specific files/directories:
      <exclude-pattern>*/Resources/views/*.php</exclude-pattern>
      
  3. Performance

    • Large projects may slow down PHPCS. Cache results with phpcs --cache (requires phpcs-cache extension).

Debugging

  • Verbose Output: Use --verbose to diagnose rule application:
    vendor/bin/phpcs --standard=./phpcs.xml --verbose src
    
  • Rule-Specific Help: Check individual rule docs (e.g., vendor/bin/phpcs --help for generic rules).

Extension Points

  1. Custom Rules

    • Extend the ruleset by adding your own .php rules (see PHPCS docs).
    • Example: Create Custom/Sunrise/Rule.php and reference it in phpcs.xml:
      <rule ref="Custom/Sunrise/Rule"/>
      
  2. Sniff Configuration

    • Override severity (e.g., treat warnings as errors):
      <config name="warning_severity" value="5"/>
      
  3. Autofix Limitations

    • phpcbf may not handle all Sunrise rules. Test fixes manually before committing.

Pro Tips

  • Baseline Violations: Use --report=summary to track progress:
    vendor/bin/phpcs --standard=./phpcs.xml --report=summary src > phpcs-baseline.txt
    
  • Git Blame Integration: Combine with git blame to identify authors of violations:
    vendor/bin/phpcs --standard=./phpcs.xml --report=gitblame src
    
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata