Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/troelskn/phpweaver

A combined runtime/static code-analysis tool, that can trace parameter types
https://github.com/troelskn/phpweaver

Last synced: about 2 months ago
JSON representation

A combined runtime/static code-analysis tool, that can trace parameter types

Awesome Lists containing this project

README

        

phpweaver
===
[![Build Status](https://travis-ci.org/AJenbo/php-tracer-weaver.svg?branch=master)](https://travis-ci.org/AJenbo/php-tracer-weaver)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cc2ad72a9e4c47a9bbc84037a29857a8)](https://www.codacy.com/app/AJenbo/php-tracer-weaver?utm_source=github.com&utm_medium=referral&utm_content=AJenbo/php-tracer-weaver&utm_campaign=Badge_Grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/412a2f0203c7ed255bee/maintainability)](https://codeclimate.com/github/AJenbo/php-tracer-weaver/maintainability)
[![BCH compliance](https://bettercodehub.com/edge/badge/AJenbo/php-tracer-weaver?branch=master)](https://bettercodehub.com/)
[![Coverage Status](https://coveralls.io/repos/github/AJenbo/php-tracer-weaver/badge.svg?branch=master)](https://coveralls.io/github/AJenbo/php-tracer-weaver?branch=master)

**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](http://www.xdebug.org/docs/execution_trace) 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.