tzmfreedom/type-tracer

0.0.4 2024-11-17 12:12 UTC

This package is auto-updated.

Last update: 2025-04-17 13:03:58 UTC


README

Type Tracer is Rector Custom Rule to add type declaration.

Install

$ composer require --dev tzmfreedom/type-tracer

Usage

  1. Generate func trace files.

If you use Laravel, FuncTraceMiddleware is available for func trace.

  1. Aggregate func trace files.
$ vendor/bin/trace-aggregate 'App\' type-aggregate.json '/tmp/trace.*'
  1. Run Rector
<?php

use Tzmfreedom\TypeTracer\Rector\TypeDeclarationRector;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withConfiguredRule(TypeDeclarationRector::class, [
        'mixedTypeCount' => 4,
        'file' => 'type-aggregate.json',
    ]);

How it works

  1. Record PHP function execution traces with arguments by Xdebug Func Trace.
  2. Aggregate function traces.
  3. Add type declaration with aggregated function traces by Rector.