pylebecq / phpqa

Docker image that provides static analysis tools for PHP

Home Page:https://hub.docker.com/r/jakzal/phpqa/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static Analysis Tools for PHP

Docker image providing static analysis tools for PHP.

Build Status Docker Build

Docker hub repository: https://hub.docker.com/r/jakzal/phpqa/

Nightly builds: https://hub.docker.com/r/jakzal/phpqa-nightly/

Available tools

Running tools

Pull the image:

docker pull jakzal/phpqa

The default command will list available tools:

docker run -it --rm jakzal/phpqa

To run the selected tool inside the container, you'll need to mount the project directory on the container with -v $(pwd):/project. Some tools like to write to the /tmp directory (like PHPStan, or Behat in some cases), therefore it's often useful to share it between docker runs, i.e. with -v $(pwd)/tmp-phpqa:/tmp.

docker run -it --rm -v $(pwd):/project -v $(pwd)/tmp-phpqa:/tmp -w /project jakzal/phpqa phpstan analyse src

You'll probably want to tweak this command for your needs and create an alias for convenience:

alias phpqa="docker run -it --rm -v $(pwd):/project -v $(pwd)/tmp-phpqa:/tmp -w /project jakzal/phpqa:alpine"

Add it to your ~/.bashrc so it's defined every time you start a new terminal session.

Now the command becomes a lot simpler:

phpqa phpstan analyse src

Building the image

git clone https://github.com/jakzal/phpqa.git
cd phpqa
make build-latest

To build the alpine version:

make build-alpine

Customising the image

It's often needed to customise the image with project specific extensions. To achieve that simply create a new image based on jakzal/phpqa:

FROM jakzal/phpqa:alpine

RUN apk add --no-cache libxml2-dev \
 && docker-php-ext-install soap

Next, build it:

docker build -t foo/phpqa .

Finally, use your customised image instead of the default one:

docker run -it --rm -v $(pwd):/project -w /project foo/phpqa phpmetrics .

Adding PHPStan extensions

Use the composer-bin-plugin to install any PHPStan extensions in the phpstan namespace:

FROM jakzal/phpqa:alpine

RUN global bin phpstan require phpstan/phpstan-phpunit

You'll be able to include them in your PHPStan configuration from the /root/.composer/vendor-bin/phpstan/vendor path:

includes:
    - /root/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-phpunit/extension.neon

Debugger & Code Coverage

The php-dbg debugger is provided by default. No additional extensions (like XDebug) are required to calculate code coverage:

phpqa phpdbg -qrr ./vendor/bin/phpunit --coverage-text

Contributing

Please read the Contributing guide to learn about contributing to this project. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

About

Docker image that provides static analysis tools for PHP

https://hub.docker.com/r/jakzal/phpqa/

License:MIT License


Languages

Language:PHP 97.1%Language:Makefile 2.9%