phpweaver is a tool for analysing parameter types in PHP code, using a combination of static and runtime analysis. It relies on the xdebug extension to trace function calls. The result of the analysis can then be used to generate docblock comments, with the proper type annotations.
The basic usage of phpweaver is to write a piece of code (If you have unit tests/examples, they would be a good candidate), that utilises the code to manipulate. Run this example with the tracer, then use weaver to generate docblocks from the trace.
example/ folder for a basic example.
The project has two main commands:
This is just a wrapper around php + xdebug. Use it in lieu of
php to execute a php script. It will run normally, but the code is traced and the output is dumped in
dumpfile.xt. You can also manually configure xdebug to generate the tracefile.
phpweaver trace test.php
If your script requires it's own paremeter you can stop paramerter pasing in bash with the duble dash:
phpweaver trace -- vendor/bin/phpunit "-c phpunit.xml"
This command takes a dumpfile (Generated by the trace process) and a php-source path (directory or file), and injects docblock comments into the php-source, using the type-information from the trace. It will look for
dumpfile.xt in the current directory, or a trace file specifyed using the --tracefile option, printing the modified file to stdout.
phpweaver weave somelibrary.php
The same dumpfile can be used to weave multiple files, by specifying a folder or multiple paths.
There is a Dockerfile for getting an environment up and running. First install docker somehow, then issue:
docker build -t phpweaver . docker run -it phpweaver
This will log you in to the machine. Run tests with:
For development, you will probably want to mount the repo into the container, so run it like this:
docker run -it --mount type=bind,source="$(pwd)",target=/usr/src/app phpweaver
Any changes you make inside the container will now be reflected on your host system.