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

Coke Laravel Package

m6web/coke

Coke is a CLI wrapper around PHP_CodeSniffer that lets you manage per-project rules via a .coke file. Run phpcs with easy include/exclude lists, optional “only git changed” mode, verbose output, and pass through any phpcs arguments.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require --dev m6web/coke
    

    (Note: Despite being deprecated, this package can still be used for legacy projects or specific use cases.)

  2. Basic Usage:

    • Run Coke to generate a .phpcs.xml or .phpcs.xml.dist configuration file:
      vendor/bin/coke generate
      
    • This creates a default PHPCS (PHP Code Sniffer) config file in your project root.
  3. First Use Case:

    • Customize the generated config (e.g., adjust standard, ruleset, or exclude paths) to match your team’s coding standards.
    • Run PHPCS with your new config:
      vendor/bin/phpcs -n --standard=./.phpcs.xml src/
      

Where to Look First

  • Generated Config: Inspect .phpcs.xml for default rules (e.g., PSR1/PSR2, custom sniffs).
  • Coke Docs: Check the archived README for legacy options (e.g., --sniffs, --exclude flags).
  • PHPCS Docs: Refer to PHP_CodeSniffer’s manual for rule details.

Implementation Patterns

Workflow Integration

  1. Onboarding New Projects:

    • Add Coke to composer.json under require-dev and run generate in post-install-cmd:
      {
        "scripts": {
          "post-install-cmd": [
            "@php ./vendor/bin/coke generate"
          ]
        }
      }
      
    • Commit .phpcs.xml to version control for consistency.
  2. Team Standardization:

    • Use Coke to bootstrap a shared config, then manually tweak rules (e.g., disable PSR12.Methods.MethodDeclaration).
    • Example customization:
      <config name="standard" value="PSR12" />
      <rule ref="PSR12" />
      <rule ref="Generic.Files.LineEndings" severity="warning" />
      
  3. CI/CD Pipeline:

    • Integrate PHPCS with Coke-generated configs in GitHub Actions/GitLab CI:
      - name: Run PHPCS
        run: vendor/bin/phpcs -n --standard=.phpcs.xml src/ tests/
      

Advanced Patterns

  • Sniff Customization:
    • Use Coke’s --sniffs flag to include custom sniffs (e.g., ./Sniffs/ClassLengthSniff.php):
      vendor/bin/coke generate --sniffs="PSR12,./Sniffs/*"
      
  • Multi-Standard Projects:
    • Generate separate configs for different directories (e.g., ./config/phpcs-frontend.xml for frontend-specific rules).

Gotchas and Tips

Pitfalls

  1. Deprecation Warning:

  2. Config Overrides:

    • Coke-generated configs may conflict with existing .phpcs.xml files. Backup before running generate.
  3. Sniff Path Issues:

    • Custom sniffs must be autoloaded or in ./Sniffs/. Coke doesn’t auto-detect Composer-autoloaded sniffs.

Debugging Tips

  • Validate Config:
    vendor/bin/phpcs --config=.phpcs.xml --test
    
  • Verbose Output: Use --verbose with Coke to debug generation:
    vendor/bin/coke generate --verbose
    

Extension Points

  1. Custom Templates:

    • Fork Coke or extend its logic by copying its template logic (PHP 5.3+).
    • Example: Add a --template flag to use a custom XML skeleton.
  2. Post-Generation Hooks:

    • Use composer scripts to run additional commands after Coke:
      {
        "scripts": {
          "post-coke": [
            "@php ./scripts/tweak-phpcs-config.php"
          ]
        }
      }
      

Performance Notes

  • Coke is not optimized for large projects. For scalability, consider:
    • Caching generated configs (e.g., via git update-index --assume-unchanged .phpcs.xml).
    • Using PHPCS’s --cache flag for faster repeated runs.

Migration Path

  • To Modern PHPCS: Replace Coke with a direct PHPCS config. Example minimal .phpcs.xml:
    <ruleset>
      <config name="standard" value="PSR12"/>
      <file>./src/</file>
    </ruleset>
    
  • For Custom Rules: Use PHPCS’s RuleSet or Config classes in PHP for dynamic generation.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor