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

Pretty Printer Laravel Package

memio/pretty-printer

Memio PrettyPrinter is an opinionated PHP code generator that takes a Model and uses a TemplateEngine to produce “pretty” code. Outputs a string you can save to files, print to console, or render in web pages.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Enhanced Developer Experience:

    • CI/CD Integration: GitHub Actions setup enables automated code generation in pipelines, reducing manual effort and ensuring consistency across environments.
    • Tooling Modernization: Replacement of custom scripts with a Makefile standardizes workflows (e.g., make generate, make test-generated), aligning with Laravel’s ecosystem (e.g., Laravel’s own Makefile patterns).
    • Static Analysis: Integration of PHPStan, Rector, and Swiss Knife elevates generated code quality by enforcing type safety, modernizing syntax (e.g., PHP 8.1+ features), and adding utility functions (e.g., Swiss Knife’s collections).
    • Docker Support: Containerized local development ensures reproducibility and simplifies onboarding for team members, especially for complex template setups.
  • Laravel Synergy (Updated):

    • PHPStan: Can leverage Laravel’s PHPStan baseline (phpstan.neon) to validate generated code against project-specific rules (e.g., custom Eloquent constraints).
    • Rector: Automatically refactors generated code to adopt new Laravel patterns (e.g., converting Route::resource() to Route::apiResource() in generated controllers).
    • Swiss Knife: Adds Laravel-friendly utilities (e.g., collect($model)->toArray()) to generated boilerplate, reducing manual imports.
    • PHP-CS-Fixer v3: Ensures generated code adheres to Laravel’s coding standards (e.g., laravel preset) out-of-the-box.
  • Limitations (Updated):

    • Tooling Complexity: Additional dev dependencies (phpstan, rector, swiss-knife) may increase build times and require maintenance (e.g., updating rulesets).
    • Docker Overhead: Containerization adds setup complexity for local development, though this is mitigated by Laravel’s native Docker support.
    • Template Rigidity: While Rector can modernize generated code, it may not handle dynamic template logic (e.g., conditional field generation based on model traits).

Integration Feasibility

  • Core Laravel Compatibility:

    • Artisan + Makefile: The Makefile can integrate seamlessly with Laravel’s Artisan commands (e.g., make generate:api User → triggers php artisan generate:api User).
    • Dev Dependency Alignment: All new tools (phpstan, rector) are already used in Laravel’s ecosystem (e.g., Laravel Shift uses Rector for migrations).
    • Docker: Compatible with Laravel Sail or custom Docker setups; templates can be mounted as volumes for live reloading.
  • Dependencies (Updated):

    • PHP Version: Requires PHP 8.1+ (unchanged), but Rector/PHPStan may enforce stricter type checks, potentially surfacing issues in existing generated code.
    • Template Engine: No changes, but PHP-CS-Fixer’s updated rules may require template adjustments (e.g., line length, array syntax).
    • Build System: Makefile replaces custom scripts, reducing fragmentation but requiring team familiarity with Makefile syntax.
  • Testing (Updated):

    • PHPStan: Add to CI to validate generated code against project-specific rules (e.g., rules.phpstan.neon).
    • Rector Tests: Verify Rector rules don’t break generated code (e.g., test rector/sets/generated-code.yaml).
    • Integration: Use Laravel’s tests/Feature/GeneratedCodeTest.php to assert generated files match expectations (e.g., assertFileExists(app_path('Http/Controllers/UserController.php'))).

Technical Risk

  • Generated Code Quality (Updated):

    • Risk: Over-aggressive Rector rules or PHPStan strictness may flag false positives in generated code (e.g., dynamic property warnings).
    • Mitigation:
      • Configure PHPStan to ignore generated files by default (ignoreFiles in phpstan.neon).
      • Use Rector’s skip rules for generated code (e.g., @skip(Rector\Rector\*GeneratedCode)).
    • Risk: Swiss Knife or Rector may introduce unintended side effects (e.g., modifying non-generated files).
    • Mitigation: Run tools in a temporary directory (e.g., tmp/generated/) and copy only the final output.
  • Template Maintenance (Updated):

    • Risk: Tooling updates (e.g., PHP-CS-Fixer v3) may break templates if they rely on deprecated rules.
    • Mitigation:
      • Pin tool versions in composer.json (e.g., php-cs-fixer: ^3.0).
      • Use .php-cs-fixer.dist.php to explicitly define Laravel-compatible rules.
    • Risk: Dockerized development may obscure template paths or file permissions.
    • Mitigation: Document volume mounts and permissions in docker-compose.yml (e.g., resources/views/templates:/app/resources/views/templates).
  • Build Process Overhead (Updated):

    • Risk: GitHub Actions + Docker + tooling may slow down CI/CD.
    • Mitigation:
      • Cache Docker layers and Composer dependencies in GitHub Actions.
      • Run generation in parallel (e.g., make generate --jobs=4).
    • Risk: Local development may become slower with Docker + tooling.
    • Mitigation: Provide a Makefile.local for non-Docker setups (e.g., make generate-local).
  • Dependency Isolation (Updated):

    • Risk: New dev dependencies may conflict with existing Laravel packages (e.g., PHPStan rules from other tools).
    • Mitigation:
      • Isolate tooling in a dev Composer platform (e.g., require-dev phpstan/phpstan:^1.0 --platform).
      • Use config/rector.php to scope Rector rules to generated directories only.

Key Questions (Updated)

  1. Tooling Adoption:
    • How will the team onboard to Makefile, Docker, and PHPStan/Rector? Will training or documentation be required?
    • Should GitHub Actions run generation only in specific branches (e.g., main) or on every PR?
  2. Generated Code Ownership:
    • Who is responsible for maintaining Rector rules and PHPStan configurations for generated code?
    • How will conflicts be resolved if generated code is manually modified (e.g., Git merge conflicts)?
  3. Performance Trade-offs:
    • What’s the acceptable CI/CD timeout for generation + tooling? (e.g., 5 minutes vs. 1 minute)
    • Should generation be split into smaller batches (e.g., per-model) to reduce memory usage?
  4. Security:
    • How will PHPStan be configured to avoid false positives in generated code (e.g., dynamic properties in API resources)?
    • Are there plans to integrate Laravel Shift or Snyk for vulnerability scanning of generated files?
  5. Template Evolution:
    • How will Rector be used to retroactively modernize existing generated code (e.g., adding #[Spatie\LaravelModelGenerator\Attributes\ApiResource])?
    • Should templates include deprecation warnings for Laravel features (e.g., Route::controller()Route::apiResource())?
  6. Alternatives:
    • Could Laravel Shift or Spatie’s Model Generator replace this package for specific use cases (e.g., API resources)?
    • Is Inertia.js or Livewire generation better handled by dedicated packages (e.g., inertiajs/inertia-laravel)?

Integration Approach

Stack Fit (Updated)

  • Laravel Ecosystem (Updated):

    • PHPStan: Integrate with Laravel’s phpstan.neon to enforce project-wide rules (e.g., disallow new Collection() in generated code).
    • Rector: Use to modernize generated code in sync with Laravel upgrades (e.g., converting Route::get() to Route::get()->name()).
    • Swiss Knife: Add Laravel-specific helpers to templates (e.g., swissknife()->eloquent($model)->toArray()).
    • Docker: Align with Laravel Sail or custom Docker setups; templates can be pre-loaded via docker-compose.yml.
    • GitHub Actions: Trigger generation on PRs or deployments (e.g., on: [push] with if: github.ref == 'refs/heads/main').
  • Template Engine (Updated):

    • Blade/Twig: No changes, but PHP-CS-Fixer v3 may require template adjustments (e.g., {{ to {{ }} spacing).
    • Makefile: Replace custom scripts with standardized targets:
      generate:php generate:api generate:livewire
      generate:php
          @php artisan generate:php User Post
      generate:api
          @php artisan generate:api User --resource=true
      test-generated:
          @phpstan analyse tmp/generated/ --level=max
          @./vendor/bin/rector process tmp/generated/ --dry-run
      
  • Tooling:

    • Artisan:
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony