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

shipmonk/coding-standard

ShipMonk’s PHP_CodeSniffer ruleset for consistent PHP style across ShipMonk packages. Install via Composer, add a phpcs.xml.dist pointing to ShipMonkCodingStandard, then run phpcs to check and phpcbf to auto-fix issues.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Run composer require --dev shipmonk/coding-standard in your Laravel project to add the package to your devDependencies.

  2. Configuration Create a phpcs.xml.dist file in your project root (if it doesn’t exist) and include the ShipMonk ruleset as shown in the README. Ensure the <rule ref="ShipMonkCodingStandard"/> line is present.

  3. First Use Case Run vendor/bin/phpcs in your terminal to analyze your codebase for violations. Start with the src/ and tests/ directories to align with ShipMonk’s conventions.


Implementation Patterns

Workflows

  1. Pre-Commit Hooks Integrate phpcs into your Git workflow using a pre-commit hook to enforce standards before code is committed. Example:

    # .git/hooks/pre-commit
    #!/bin/sh
    vendor/bin/phpcs --standard=ShipMonkCodingStandard src/ tests/ || exit 1
    
  2. CI/CD Pipeline Add a step in your CI (e.g., GitHub Actions, GitLab CI) to run phpcs and fail the build if violations are found. Example GitHub Actions snippet:

    - name: Run PHP_CodeSniffer
      run: vendor/bin/phpcs --standard=ShipMonkCodingStandard --warning-severity=0 src/ tests/
    
  3. Auto-Fixing Use phpcbf to automatically fix common issues (e.g., indentation, spacing) before code reviews:

    vendor/bin/phpcbf --standard=ShipMonkCodingStandard src/
    
  4. Custom Rulesets Extend the ShipMonk ruleset by creating a custom phpcs.xml file that overrides specific rules:

    <ruleset>
        <rule ref="ShipMonkCodingStandard">
            <exclude name="PSR12.Methods.MethodDeclaration"/>
        </rule>
    </ruleset>
    

Integration Tips

  • Laravel-Specific Adjustments Exclude Laravel-specific files (e.g., vendor/, bootstrap/) from analysis by adding:

    <exclude-pattern>vendor/</exclude-pattern>
    <exclude-pattern>bootstrap/</exclude-pattern>
    
  • Team Onboarding Document the coding standard in your CONTRIBUTING.md and include a one-time phpcbf run for new contributors to align their codebase.

  • Partial Runs Target specific directories or files for faster feedback during development:

    vendor/bin/phpcs src/Http/Controllers/
    

Gotchas and Tips

Pitfalls

  1. Rule Conflicts ShipMonk’s ruleset may conflict with other installed coding standards (e.g., slevomat/coding-standard). Ensure only ShipMonk’s ruleset is referenced in phpcs.xml.dist to avoid ambiguity.

  2. False Positives Some rules (e.g., line length) may flag Laravel-specific constructs (e.g., long controller methods). Use <exclude> or <severity> tags to adjust:

    <rule ref="ShipMonkCodingStandard">
        <severity name="PSR12.Files.FileOpeningComment.SpacingAfterComment" value="warning"/>
    </rule>
    
  3. Performance Caching (<arg name="cache" value="var/phpcs.cache"/>) speeds up repeated runs but may cause stale results if the ruleset updates. Clear the cache with:

    rm -rf var/phpcs.cache
    
  4. Auto-Fix Limitations phpcbf won’t fix all issues (e.g., semantic violations). Review output manually for unresolved warnings.

Debugging

  • Verbose Output Use --verbose to debug rule application:

    vendor/bin/phpcs --standard=ShipMonkCodingStandard --verbose src/
    
  • Rule Explanation Check the slevomat/coding-standard docs for details on individual rules, as ShipMonk’s ruleset builds on top of it.

Extension Points

  1. Custom Rules Add project-specific rules by extending the ruleset:

    <rule ref="ShipMonkCodingStandard">
        <config name="custom_rules" value="vendor/your-package/coding-standard"/>
    </rule>
    
  2. Severity Adjustments Temporarily lower severity for specific rules during refactoring:

    <rule ref="ShipMonkCodingStandard">
        <severity name="PSR12.ControlStructures.SpaceAfterControlStructure" value="warning"/>
    </rule>
    
  3. Sniffs Configuration Fine-tune individual sniffs (e.g., line length) via the <config> tag:

    <config name="line_ending" value="LF"/>
    
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope