Skip to content

Instantly share code, notes, and snippets.

@amnuts
Created October 3, 2023 10:59

Revisions

  1. amnuts created this gist Oct 3, 2023.
    19 changes: 19 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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
    17 changes: 17 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    First build the docker image

    ```bash
    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:

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

    or:

    ```bash
    ./runon.sh /path/to/your/php/files
    ```
    12 changes: 12 additions & 0 deletions runon.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/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