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 Code Validator Laravel Package

flyeralarm/php-code-validator

FLYERALARM PHP coding guideline validator: a PSR-12 based PHP_CodeSniffer ruleset with extra standards like lowerCamelCase variables, no Yoda conditions, bans on eval/goto, namespace underscores, and certain class suffixes. Easy Composer embed via ruleset.xml.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • PSR-12 Foundation: The package extends PSR-12, which is already a de facto standard in Laravel ecosystems (e.g., Laravel Framework, Forge, Envoyer). This ensures minimal disruption to existing codebases while enforcing consistency.
  • Laravel-Specific Customizations: The package’s rules (e.g., lowerCamelCase variables, no Interface suffixes) may clash with Laravel conventions (e.g., UserRepositoryInterface, AppServiceProvider). A strategic override (via phpcs.xml) will be required to exclude or modify conflicting rules.
  • Static Analysis Synergy: Complements Laravel’s tooling stack:
    • PHPStan/Psalm: For type safety (this package handles style, not logic).
    • Laravel Pint: For auto-formatting (this package focuses on validation).
    • Laravel Valet/Sail: Can integrate phpcs into local/dev environments.
  • Extensibility: PHP_CodeSniffer’s rule system allows adding Laravel-specific sniffs (e.g., validating Eloquent relationships, Blade template syntax). Example: A custom rule to enforce snake_case for database columns.

Integration Feasibility

  • Composer Integration: Lightweight dev dependency with zero runtime overhead. No Laravel service provider or configuration required.
  • CI/CD Readiness:
    • GitHub Actions/GitLab CI: Can be added as a pre-commit or pre-merge step (e.g., fail builds on violations).
    • Parallelization: Supports multi-file/multi-directory checks (e.g., vendor/bin/phpcs app/ tests/).
    • Caching: PHP_CodeSniffer’s --cache flag reduces CI/CD runtime.
  • IDE Support: Works with PHPStorm, VSCode (PHP Intelephense), and Laravel IDE Helper for real-time feedback.
  • Docker Compatibility: Pre-built Docker images for PHP 8.2–8.5 align with Laravel’s LTS support (PHP 8.2+) and newer versions.

Technical Risk

Risk Impact Mitigation Strategy
Rule Conflicts High (e.g., Interface suffixes) Override rules in phpcs.xml or exclude paths (e.g., <exclude-pattern>*/Interfaces/*.php</exclude-pattern>).
Performance in CI/CD Medium (slower pipelines) Cache results (--cache), parallelize checks, or run only on changed files (git diff).
Maintenance Overhead Low-Medium Monitor Laravel’s coding standards and update rules annually.
False Positives/Negatives Low Test against Laravel’s core codebase to validate rule accuracy.
Dependency Bloat Low Dev-only dependency; no impact on production.

Key Questions

  1. Rule Customization:

    • Which of the package’s custom rules conflict with Laravel’s conventions (e.g., Interface suffixes, exception message formatting)?
    • Should we whitelist/blacklist specific files/directories (e.g., exclude app/Interfaces/)?
  2. CI/CD Strategy:

    • Should violations fail builds (strict) or warn only (lenient)?
    • How to handle auto-fixable vs. manual-fix violations (e.g., sniff-fix for safe changes)?
  3. IDE vs. CLI:

    • Should we prioritize real-time IDE feedback (PHPStorm/VSCode) or CI/CD enforcement?
    • How to balance developer productivity (quick fixes) with team consistency (enforced standards)?
  4. Laravel-Specific Extensions:

    • Should we add custom sniffs for Laravel-specific checks (e.g., Eloquent query validation, Blade syntax)?
    • How to integrate with Laravel Pint (auto-formatter) vs. this package (validator)?
  5. PHP Version Support:

    • Should we pin to a specific PHP_CodeSniffer version (e.g., 3.13.5) for stability, or allow updates?
    • How to handle legacy Laravel projects (e.g., PHP 7.4) vs. newer stacks (PHP 8.2+)?
  6. Onboarding Impact:

    • How to train developers on the new rules (e.g., documentation, workshops)?
    • Should we grandfather existing code or enforce rules retroactively?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Aligns with PSR-12, PHP_CodeSniffer, and Laravel’s tooling (e.g., php artisan, Valet, Sail).
  • DevOps Tools:
    • GitHub Actions/GitLab CI: Native support for phpcs commands.
    • Docker: Pre-built images for multi-PHP-version testing.
    • Pre-commit Hooks: Integrate with pre-commit (e.g., via husky or laravel/git-hooks).
  • IDE Compatibility:
    • PHPStorm: Native PHP_CodeSniffer integration.
    • VSCode: Extensions like PHP Intelephense or PHP CS Fixer.
  • Auto-Formatting Synergy:
    • Pair with Laravel Pint (auto-formatter) for a validate-then-fix workflow:
      make sniff       # Validate
      make sniff-fix   # Auto-fix safe issues
      laravel-pint     # Auto-format remaining style
      

Migration Path

Phase Action Tools/Commands
Assessment Audit existing codebase for conflicts with custom rules (e.g., Interface suffixes). vendor/bin/phpcs --report=xml --standard=vendor/flyeralarm/php-code-validator/ruleset.xml app/
Configuration Create phpcs.xml to override/extend rules. Example: Custom Ruleset Template
CI/CD Integration Add phpcs to CI pipeline (e.g., GitHub Actions). .github/workflows/phpcs.yml
IDE Setup Configure PHPStorm/VSCode for real-time validation. PHPStorm Guide
Developer Onboarding Document rules and provide sniff-fix workflow examples. README.md section on coding standards.
Retroactive Enforcement Decide: Enforce on new code only, or apply to legacy code with exceptions. Use <exclude-pattern> in phpcs.xml for legacy paths.

Compatibility

  • Laravel Versions: Supports LTS (10.x, 11.x) and newer (PHP 8.2+). For older versions (e.g., PHP 7.4), use compatibility layers (e.g., composer.phar updates).
  • PHP_CodeSniffer: Requires PHP_CodeSniffer 3.x (included as a dependency). No conflicts with other static analyzers (PHPStan/Psalm).
  • Auto-Fixers: Works alongside PHP-CS-Fixer and Laravel Pint (avoid rule duplication).
  • Windows/Linux/macOS: Cross-platform support (tested via GitHub Actions).

Sequencing

  1. Phase 1: Validation-Only Mode
    • Integrate phpcs into CI/CD as a warning-only check.
    • Example GitHub Action:
      - name: PHP Code Sniffer
        run: vendor/bin/phpcs --standard=vendor/flyeralarm/php-code-validator/ruleset.xml --warning-severity=0 app/ tests/
      
  2. Phase 2: Enforcement Mode
    • Update to fail builds on violations (after developer buy-in).
  3. Phase 3: Auto-Fix Integration
    • Add sniff-fix to pre-commit hooks or CI (for safe changes).
  4. Phase 4: Custom Rules
    • Extend ruleset for Laravel-specific checks (e.g., Eloquent validation).

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor PHP_CodeSniffer and FLYERALARM’s ruleset for breaking changes.
    • Update annually or when Laravel releases new coding standards.
  • Rule Maintenance:
    • Deprecation: Remove obsolete rules (e.g., ReturnTypeSniff was dropped in favor of PHPStan).
    • Additions: Extend for Laravel-specific needs (e.g., Blade syntax, Facade usage).
  • Tooling:
    • PHP_CodeSniffer: Requires occasional updates (e.g., 3.13.5 → 3.14.x).
    • Composer: Ensure compatibility with
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
andydefer/laravel-cluster
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