Coder Social home page Coder Social logo

docker-image's Introduction

Docker image for PHPStan - PHP Static Analysis Tool

Build Status Docker Automated build Docker Stars Docker Pulls

The image is based on Alpine Linux and built daily.

Supported tags

How to use this image

Install

Install the container:

docker pull phpstan/phpstan

Alternatively, pull a specific version:

docker pull phpstan/phpstan:0.10

Usage

We are recommend to use the images as an shell alias to access via short-command. To use simply phpstan everywhere on CLI add this line to your ~/.zshrc, ~/.bashrc or ~/.profile.

alias phpstan='docker run -v $PWD:/app --rm phpstan/phpstan'

If you don't have set the alias, use this command to run the container:

docker run --rm -v /path/to/app:/app phpstan/phpstan [some arguments for PHPStan]

For example:

docker run --rm -v /path/to/app:/app phpstan/phpstan analyse /app/src

Customizing

Install PHPStan extensions

If you need an PHPStan extension, for example phpstan/phpstan-phpunit, you can simply extend an existing image and add the relevant extension via Composer. In some cases you need also some additional PHP extensions like DOM. (see section below)

Here is an example Dockerfile for phpstan/phpstan-phpunit:

FROM phpstan/phpstan:0.9
RUN apk --update --progress --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.7/community add \
    php7-dom \
    php7-xmlwriter \
    && composer global require phpstan/phpstan-phpunit

Further PHP extension support

Sometimes your codebase requires some additional PHP extensions like "intl" or maybe "soap".

Therefore you need to know that our Docker image extends the official alpine Docker image. So only a subset of extensions are pre-installed. Also because PHPStan needs no further extensions to run itself.

But to solve this issue you can extend our Docker image in an own Dockerfile like this, for example to add "soap" and "intl":

FROM phpstan/phpstan:latest
RUN apk --update --progress --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.7/community add \
    icu-dev \
    libxml2-dev \
    php7-soap \
    php7-intl

Missing classes like "PHPUnit_Framework_TestCase"

Often you use PHAR files like PHPUnit in your projects. These PHAR files provide sometimes own classes where your project classes extends from. But these cannot be found in the vendor directory and so cannot be autoloaded. So you see error messages like this: "Fatal error: Class 'PHPUnit_Framework_TestCase' not found"

To solve this issue you need an own configuration file, like "phpstan.neon". This file can look like this:

parameters:
	autoload_files:
		- path/to/phpunit.phar

After creating this file in your project root you can run PHPStan for example via

docker run -v $PWD:/app --rm phpstan/phpstan -c phpstan.neon --level=4

and now the required classes are loaded. Please take also a look in the relevant part at the PHPStan documentation.

docker-image's People

Contributors

fuco1 avatar mablae avatar ondram avatar tommy-muehle avatar vitr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.