Skip to content

tba77/docker-phplint

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker image for phplint

Build Status Tag License

All #awesome-ci Docker images

ansible ansible-lint awesome-ci black checkmake eslint file-lint gofmt goimports golint jsonlint phpcbf phpcs phplint php-cs-fixer pycodestyle pylint terraform-docs terragrunt terragrunt-fmt yamlfmt yamllint

All #awesome-ci Makefiles

Visit cytopia/makefiles for seamless project integration, minimum required best-practice code linting and CI.

View Dockerfile on GitHub.

Docker hub

Tiny Alpine-based dockerized version of PHP[1], which defaults to linting mode and adds the option to ignore files and paths. The image is built nightly against multiple stable versions and pushed to Dockerhub.

Available Docker image versions

Docker tag PHP Version
latest Latest stable version
7.3 Latest stable 7.3.x version
7.2 Latest stable 7.2.x version
7.1 Latest stable 7.1.x version
7.0 Latest stable 7.0.x version
5.6 Latest stable 5.6.x version

Docker mounts

The working directory inside the Docker container is /data/ and should be mounted locally to where your PHP code is located

Usage

Generic

$ docker run -it --rm cytopia/phplint --help
Usage: cytopia/phplint [-i] <PATH-TO-FILE>
       cytopia/phplint [-i] <GLOB-PATTERN>
       cytopia/phplint --version
       cytopia/phplint --help

 -i <GLOB-PATTERN>  Ignore glob pattern when using the GLOB-PATTERN for file search.
                    (e.g.: -i '\.test*.php')
 <PATH-TO-FILE>     Path to file to validate
 <GLOB-PATTERN>     Glob pattern for recursive scanning. (e.g.: *\.php)
                    Anything that "find . -name '<GLOB-PATTERN>'" will take is valid.

Lint PHP files

$ docker run -it --rm -v $(pwd):/data cytopia/phplint
find . -name "*.php" -type f -print0
php -d display_errors=1 -d error_reporting=-1 -l ./index.php
php -d display_errors=1 -d error_reporting=-1 -l ./config.php
php -d display_errors=1 -d error_reporting=-1 -l ./settings.php

Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in ./settings.php on line 4

Example Makefile

You can add the following Makefile to your project for easy generation of PHP linting.

ifneq (,)
.error This Makefile requires GNU Make.
endif

.PHONY: lint _update-phplint
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

VERSION = 7.3
IGNORES = ./vendor/*

lint: _update-phplint
	docker run -it --rm cytopia/phplint:${VERSION} -i ${IGNORES} '*.php'

_update-phplint:
	docker pull cytopia/phplint:${VERSION}

Travis CI integration

With the above Makefile in place, you can easily add a Travis CI rule to ensure the terraform-docs output is always up-to-date and will fail otherwise (due to git changes):

---
sudo: required
language: minimal
services:
  - docker
script:
  - make lint

Related #awesome-ci projects

Docker images

Save yourself from installing lot's of dependencies and pick a dockerized version of your favourite linter below for reproducible local or remote CI tests:

GitHub DockerHub Type Description
awesome-ci aci-hub-img Basic Tools for git, file and static source code analysis
file-lint flint-hub-img Basic Baisc source code analysis
ansible ansible-hub-img Ansible Multiple versions and flavours of Ansible
ansible-lint alint-hub-img Ansible Lint Ansible
gofmt gfmt-hub-img Go Format Go source code [1]
goimports gimp-hub-img Go Format Go source code [1]
golint glint-hub-img Go Lint Go code
eslint elint-hub-img Javascript Lint Javascript code
jsonlint jlint-hub-img JSON Lint JSON files [1]
checkmake cm-hub-img Make Lint Makefiles
phpcbf pcbf-hub-img PHP PHP Code Beautifier and Fixer
phpcs pcs-hub-img PHP PHP Code Sniffer
phplint plint-hub-img PHP PHP Code Linter [1]
php-cs-fixer pcsf-hub-img PHP PHP Coding Standards Fixer
black black-hub-img Python The uncompromising Python code formatter
pycodestyle pycs-hub-img Python Python style guide checker
pylint pylint-hub-img Python Python source code, bug and quality checker
terraform-docs tfdocs-hub-img Terraform Terraform doc generator (TF 0.12 ready) [1]
terragrunt tg-hub-img Terraform Terragrunt and Terraform
terragrunt-fmt tgfmt-hub-img Terraform terraform fmt for Terragrunt files [1]
yamlfmt yfmt-hub-img Yaml Format Yaml files [1]
yamllint ylint-hub-img Yaml Lint Yaml files

[1] Uses a shell wrapper to add enhanced functionality not available by original project.

Makefiles

Visit cytopia/makefiles for dependency-less, seamless project integration and minimum required best-practice code linting for CI. The provided Makefiles will only require GNU Make and Docker itself removing the need to install anything else.

License

MIT License

Copyright (c) 2019 cytopia

About

Alpine-based version of PHP for linting and reproducible usage in CI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Makefile 49.9%
  • Shell 44.2%
  • Dockerfile 3.2%
  • PHP 2.7%