├── .github └── workflows │ └── dockerpush.yml ├── Dockerfile ├── LICENSE └── README.md /.github/workflows/dockerpush.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | 3 | on: 4 | push: 5 | # Publish `master` as Docker `latest` image. 6 | branches: 7 | - master 8 | 9 | # Publish `v1.2.3` tags as releases. 10 | tags: 11 | - v* 12 | 13 | # Run tests for any PRs. 14 | pull_request: 15 | 16 | jobs: 17 | # Run tests. 18 | # See also https://docs.docker.com/docker-hub/builds/automated-testing/ 19 | test: 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Run tests 26 | run: | 27 | if [ -f docker-compose.test.yml ]; then 28 | docker-compose --file docker-compose.test.yml build 29 | docker-compose --file docker-compose.test.yml run sut 30 | else 31 | docker build . --file Dockerfile 32 | fi 33 | 34 | # Push image to GitHub Package Registry. 35 | # See also https://docs.docker.com/docker-hub/builds/ 36 | push: 37 | # Ensure test job passes before pushing image. 38 | needs: test 39 | 40 | runs-on: ubuntu-latest 41 | if: github.event_name == 'push' 42 | 43 | steps: 44 | - uses: actions/checkout@v2 45 | 46 | - name: Build image 47 | run: docker build . --file Dockerfile --tag image 48 | 49 | - name: Log into docker hub 50 | run: echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u fortrabbitadmin --password-stdin 51 | 52 | - name: Push image 53 | run: | 54 | IMAGE_ID=frbit/phpco 55 | 56 | # Strip git ref prefix from version 57 | VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') 58 | 59 | # Strip "v" prefix from tag name 60 | [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') 61 | 62 | # Use Docker `latest` tag convention 63 | [ "$VERSION" == "master" ] && VERSION=latest 64 | 65 | echo IMAGE_ID=$IMAGE_ID 66 | echo VERSION=$VERSION 67 | 68 | docker tag image $IMAGE_ID:$VERSION 69 | docker push $IMAGE_ID:$VERSION 70 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.0-cli-alpine 2 | 3 | # Install PHP CodeSniffer 4 | ARG PHPCS_RELEASE="3.6.0" 5 | RUN pear install PHP_CodeSniffer-$PHPCS_RELEASE 6 | 7 | # Install the PHPCompatibility standard 8 | ARG PHPCOMP_RELEASE="9.3.5" 9 | RUN set -eux &&\ 10 | apk --no-cache add git &&\ 11 | mkdir -p "/opt/" &&\ 12 | cd "/opt/" &&\ 13 | git clone -v --single-branch --depth 1 https://github.com/PHPCompatibility/PHPCompatibility.git --branch $PHPCOMP_RELEASE &&\ 14 | rm -rf PHPCompatibility/.git &&\ 15 | apk del git 16 | 17 | # Configure phpcs defaults 18 | RUN phpcs --config-set installed_paths /opt/PHPCompatibility &&\ 19 | phpcs --config-set default_standard PHPCompatibility &&\ 20 | phpcs --config-set testVersion 8.0 &&\ 21 | phpcs --config-set report_width 120 22 | 23 | # Configure PHP with all the memory we might need (unlimited) 24 | RUN echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/memory.ini 25 | 26 | WORKDIR /mnt/src 27 | 28 | ENTRYPOINT ["/usr/local/bin/phpcs"] 29 | 30 | CMD ["-p", "--colors", "."] 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 fortrabbit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phpco 2 | 3 | ⚠️ Unmaintained and archived! 4 | 5 | An installation of PHP8 and [PHP Compatibility](https://github.com/PHPCompatibility/PHPCompatibility) in a small Alpine Linux Docker image. 6 | 7 | ## PHPCompatibility 8 | 9 | PHPCompatibility is built as a _code standard_ for the `phpcs` command. It searches your code for patterns matching a long list of deprecated functions and use cases. It gives very direct instructions about what might be deprecated, wrong or risky with your code on any specified PHP version. 10 | 11 | ## Motivations 12 | 13 | Using PHPCompatibility requires you to first install PHP CodeSniffer globally and then configure PHPCompatibility as the code standard to use. We find that the easiest way to run it is with Docker, since that cleanly separates your local PHP setup from the tool. 14 | 15 | ## Getting phpco-docker 16 | 17 | The easiest way is to create a shell function for `phpco`. No need to clone this repository. First make sure you have [Docker](https://docs.docker.com/install) installed on your machine. Then execute this in your local terminal: 18 | 19 | ```sh 20 | phpco() { docker run --init -v $PWD:/mnt/src:cached --rm -u "$(id -u):$(id -g)" frbit/phpco:latest $@; return $?; } 21 | ``` 22 | 23 | You can also add this snippet to your `.bashrc` or similar shell startup script. That way it will always be available whenever you open a new shell. 24 | 25 | ## Running phpco-docker 26 | Now you can directly use the tool. This command will do a full check of all your code in the current directory for PHP 8.0 compatibility. 27 | ``` 28 | phpco -p --colors --extensions=php --runtime-set testVersion 8.0 . 29 | ``` 30 | 31 | As it completes you will see a list of found warnings and errors in your code. If you are getting a lot of warnings, but only want to deal with the stuff that will actually break, add `-n` to only show errors. 32 | 33 | If you have also updated all of your dependencies and are sure they support the PHP version you want to migrate to, you can exclude the `vendor` folder completely to only check your own code. Checking for PHP version 8.0 is the default so we can also remove that part. 34 | 35 | ``` 36 | phpco -p --colors --extensions=php . -n --ignore="vendor/" 37 | ``` 38 | 39 | Remember: Since this is running within a docker container, the paths to your source files will start with `/mnt/src/` instead of the actual absolute path on your host computer. 40 | 41 | [Read more about available flags specific to PHP Compatibility](https://github.com/PHPCompatibility/PHPCompatibility) and about the [underlying options for PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage). 42 | --------------------------------------------------------------------------------