Skip to content

Latest commit

 

History

History
63 lines (38 loc) · 3.02 KB

README.markdown

File metadata and controls

63 lines (38 loc) · 3.02 KB

phpweaver

Build Status Codacy Badge Maintainability BCH compliance Coverage Status

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.

Usage

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.

See the example/ folder for a basic example.

The project has two main commands:

  • trace
  • weave

trace

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.

Sample usage:

phpweaver trace test.php

If your script requires it's own paremeter you can stop paramerter pasing in bash with the double dash:

phpweaver trace -- vendor/bin/phpunit "-c phpunit.xml"

weave

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.

Sample usage:

phpweaver weave somelibrary.php

The same dumpfile can be used to weave multiple files, by specifying a folder or multiple paths.

Running tests

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:

phpunit

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.