Skip to content

Instantly share code, notes, and snippets.

@amnuts
Created October 3, 2023 10:59
Show Gist options
  • Save amnuts/a6f1ac598a396f3ff3862b46c2eadaf0 to your computer and use it in GitHub Desktop.
Save amnuts/a6f1ac598a396f3ff3862b46c2eadaf0 to your computer and use it in GitHub Desktop.
Run PHPCompatibility/PHPCompatibility on a directory using docker containers

First build the docker image

docker build -t php-compatibility-checker .

Then you can use the runon script to start the the check on the docker container. The path supplied can be relative (assumes you have readlink installed on your machine) or absolute, and works to check that single location for all the PHP files not excluded by the ignore rules in the script:

./runon.sh ../../path/to/your/php/files

or:

./runon.sh /path/to/your/php/files
FROM php:8.2-cli
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN apt-get update && apt-get install -y --no-install-recommends git curl zip unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /var/cache/apk/* /usr/share/man /tmp/*
RUN composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
RUN composer global require "squizlabs/php_codesniffer=*"
RUN composer global require "phpcompatibility/php-compatibility:dev-develop"
RUN composer global require "phpunit/phpunit=*"
RUN /root/.composer/vendor/bin/phpcs --config-set installed_paths "/root/.composer/vendor/phpcompatibility/php-compatibility"
RUN composer global update --lock
WORKDIR /app
VOLUME /app
#!/bin/bash
if [[ "$1" == "" ]]; then
echo "Usage: $0 <path to check>"
exit 1
fi
MOUNT_PATH=$(readlink -f "$1")
docker run --rm -v "$MOUNT_PATH:/app" php-compatibility-checker /root/.composer/vendor/bin/phpcs \
-d memory_limit=1G --standard=PHPCompatibility --runtime-set testVersion 8.2 --extensions=php \
--ignore=*/vendor/* --ignore=*/storage/* --ignore=*/bootstrap/cache/* --ignore=*/tests/* -p \
/app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment