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

Yoastcs Laravel Package

yoast/yoastcs

Yoast Coding Standards (YoastCS) provides Composer-installable rulesets for PHP_CodeSniffer plus PHP Parallel Lint, bundling Yoast sniffs and selected external standards (including WordPress). Use it to enforce consistent code style and quality in Yoast projects.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Laravel/WordPress Synergy: YoastCS integrates seamlessly with Laravel projects leveraging WordPress core (e.g., via Laravel WordPress plugins like laravel-wordpress). The WordPress ruleset aligns with WordPress VIP standards, which are often adopted in high-scale Laravel-WP integrations.
    • Modular Standards: Combines PHPCompatibilityWP (critical for Laravel’s PHP version flexibility), SlevomatCodingStandard (modern PHP best practices), and VariableAnalysis (static analysis for bugs). This covers linting, static analysis, and compatibility—three pillars of Laravel maintainability.
    • Threshold-Based Enforcement: The Threshold report enables CI/CD gatekeeping (e.g., blocking merges if errors exceed YOASTCS_THRESHOLD_ERRORS), which is invaluable for Laravel’s iterative development cycles.
    • Parallel Linting: PHP Parallel Lint reduces CI feedback latency, critical for Laravel’s monolithic-to-microservices transitions where large codebases are common.
  • Gaps:

    • Laravel-Specific Sniffs: Missing Laravel-specific rules (e.g., Eloquent query validation, Blade template standards). Would require custom sniffs or exclusion overrides.
    • Dependency Conflicts: PHPCompatibilityWP’s alpha dependency (^3.0.0@alpha) may clash with Laravel’s stable PHP version requirements (e.g., 8.1+). Requires minimum-stability: "dev" in composer.json.
    • No Laravel Artisan Integration: Lacks native Laravel command hooks (e.g., php artisan yoast:lint). Would need custom Artisan commands or Git hooks.

Integration Feasibility

  • Composer Integration: Zero-config for Laravel (adds to dev dependencies via composer require --dev yoast/yoastcs). Automatically registers with PHP_CodeSniffer.
  • CI/CD Plugins: Works with GitHub Actions, GitLab CI, and CircleCI via vendor/bin/phpcs --report=YoastCS\Yoast\Reports\Threshold. Example:
    # GitHub Actions
    - name: Run YoastCS
      run: composer check-cs-thresholds
    
  • IDE Support: PhpStorm integration via "PHP Code Sniffer Validation" (no extra setup beyond installation).

Technical Risk

  • High:
    • Breaking Changes: PHPCompatibilityWP’s alpha dependency risks instability. Test thoroughly with Laravel’s PHP version matrix (e.g., 8.0–8.3).
    • Custom Sniff Conflicts: Yoast’s WordPress.WP.GetMetaSingle sniff may conflict with Laravel’s wp_ prefix conventions (e.g., wp_get_post_meta). Requires .phpcs.xml.dist overrides.
    • Performance: Parallel Lint scales poorly on Windows CI agents (due to process limitations). Mitigate with parallel-lint --exclude vendor or agent-specific optimizations.
  • Medium:
    • Learning Curve: Developers unfamiliar with PHPCS may resist adopting YoastCS’s strict rules (e.g., SlevomatCodingStandard.Arrays.ArrayAccess). Pair with interactive training (e.g., PHPCS --generator=Text docs).
    • False Positives: PHPCompatibilityWP may flag Laravel’s polyfills (e.g., array_column in PHP 7.4). Requires minimum_wp_version tuning in .phpcs.xml.dist.

Key Questions

  1. Laravel-WordPress Hybrid Projects:
    • How will YoastCS handle Laravel-specific code (e.g., Service Providers, Blade templates) vs. WordPress core? Answer: Exclude Laravel directories in .phpcs.xml.dist or create custom sniffs.
    • Example exclusion:
      <arg value="--exclude=app/Providers,resources/views"/>
      
  2. CI/CD Strategy:
    • Should thresholds (YOASTCS_THRESHOLD_ERRORS) be project-specific (e.g., 0 for core, 5 for features) or team-wide? Answer: Start with team-wide defaults; allow overrides via environment variables.
  3. Performance:
    • How will Parallel Lint impact CI runtime for large Laravel repos (e.g., 10K+ files)? Answer: Benchmark with --exclude vendor and consider caching (e.g., GitHub Actions actions/cache).
  4. Developer Adoption:
    • What’s the ramp-up time for Laravel devs to internalize YoastCS rules? Answer: Prioritize actionable feedback (e.g., PHPCS --diff for pull requests) and pair with autofix scripts (e.g., phpcbf for warnings).

Integration Approach

Stack Fit

  • Laravel Core: YoastCS is compatible with Laravel’s PHP ecosystem but requires opt-in adoption for non-WordPress projects. Ideal for:
    • Laravel plugins extending WordPress (e.g., laravel-wordpress).
    • Projects using WordPress VIP standards (e.g., high-traffic sites).
  • Stack Conflicts:
    • Laravel Mix/Webpack: No impact (YoastCS targets PHP only).
    • Homestead/Vagrant: Parallel Lint may need memory adjustments (php-parallel-lint defaults to 4 processes; increase to 8 for CI).
    • Docker: Ensure PHP version in containers matches Laravel’s (e.g., FROM laravel:8.1 + yoast/yoastcs:^3.0).

Migration Path

  1. Assessment Phase:
    • Run composer require --dev yoast/yoastcs in a staging branch.
    • Generate baseline violations:
      vendor/bin/phpcs --standard=Yoast --report=full app/ --exclude vendor
      
    • Triage false positives (e.g., Laravel’s array_column usage).
  2. Incremental Rollout:
    • Phase 1: Enforce errors only in CI (set YOASTCS_THRESHOLD_ERRORS=0).
    • Phase 2: Add warnings to CI (set YOASTCS_THRESHOLD_WARNINGS=5).
    • Phase 3: Enforce locally via pre-commit hooks (e.g., Husky + PHPCS).
  3. Customization:
    • Override .phpcs.xml.dist to:
      • Exclude Laravel-specific files/directories.
      • Adjust minimum_wp_version (e.g., 6.0 for Laravel-WP hybrids).
      • Example:
        <config name="minimum_wp_version" value="6.0"/>
        <exclude-pattern>*/Tests/*</exclude-pattern>
        

Compatibility

Component Compatibility Mitigation
Laravel 8.x–10.x ✅ Full (PHP 8.0+ supported) Use minimum-stability: "dev" if needed.
WordPress 6.0+ ✅ Full (PHPCompatibilityWP aligned) Set minimum_wp_version in .phpcs.xml.
PHP 7.4–8.3 ✅ Full Test with php-parallel-lint in CI.
Homestead/Docker ✅ Full Match PHP version in containers.
CI (GitHub/GitLab) ✅ Full Cache vendor/ to reduce runtime.

Sequencing

  1. Pre-requisites:
    • Laravel project with Composer and PHP_CodeSniffer installed.
    • CI pipeline with PHP 8.1+ (recommended).
  2. Installation:
    composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
    composer require --dev yoast/yoastcs:"^3.0"
    
  3. Configuration:
    • Add to composer.json:
      "scripts": {
        "lint": "phpcs --standard=Yoast --report=full --exclude vendor",
        "lint:threshold": "phpcs --standard=Yoast --report=YoastCS\\Yoast\\Reports\\Threshold"
      }
      
    • Create .phpcs.xml.dist with exclusions.
  4. CI Integration:
    • GitHub Actions example:
      - name: Lint PHP with YoastCS
        run: composer lint:threshold
        env:
          YOASTCS_THRESHOLD_ERRORS: 0
          YOASTCS_THRESHOLD_WARNINGS: 5
      

Operational Impact

Maintenance

  • Pros:
    • Self-Healing: PHPCS autofix (phpcbf) can resolve warnings (e.g., spacing, heredoc formatting).
    • Centralized Rules: Single source of truth for coding standards (reduces "style wars").
    • Low Overhead: No runtime impact; runs only during development/lint
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