overtrue / phplint

:bug: A tool that can speed up linting of php files by running several lint processes at once.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[9.0.x] PHPLint Docker image should be able to lint all PHP 8 supported syntaxes

llaville opened this issue · comments

New Issue

Output of `docker inspect overtrue/phplint:latest` command
[
    {
        "Id": "sha256:8b68108fca3e26e051327334f7adfb97ebfb6c0523a4f6c9a72764bb89582caf",
        "RepoTags": [
            "overtrue/phplint:latest"
        ],
        "RepoDigests": [
            "overtrue/phplint@sha256:b0b753d246846f84bc2e3b7c55b750fca86f4e70c87f8d671f3908aa298a03a8"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2023-02-17T12:49:40.026263654Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tdpkg-dev dpkg \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkgconf \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
                "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
                "PHP_LDFLAGS=-Wl,-O1 -pie",
                "GPG_KEYS=1729F83938DA44E27BA0F4D3DBDB397470D12172 BFDDD28642824F8118EF77909B67A5C12229118F 2C16C765DBE54A088130F1BC4B9B5F600B55F3B4",
                "PHP_VERSION=8.0.28",
                "PHP_URL=https://www.php.net/distributions/php-8.0.28.tar.xz",
                "PHP_ASC_URL=https://www.php.net/distributions/php-8.0.28.tar.xz.asc",
                "PHP_SHA256=5e07278a1f315a67d36a676c01343ca2d4da5ec5bdb15d018e4248b3012bc0cd"
            ],
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "/workdir",
            "Entrypoint": [
                "/entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 88098213,
        "VirtualSize": 88098213,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/f8730ab2277ccf8bb8bc7da612e0eb165f2cf4fede9c4e6d7bbf4f2cb6d261d9/diff:/var/lib/docker/overlay2/32e453c5a9aa0c841bd4296f65ea0a7586dec7ed30192589ce4a48627ee53189/diff:/var/lib/docker/overlay2/bfe1862727cdd4ca30c6a2ed1b639aa8d8fb5ddceff933a12364ceb9c7467cc3/diff:/var/lib/docker/overlay2/4967f09eeb064c11b1e74b0b81cf0d8503edc75060d26d4ecd7c51d1f8f5047f/diff:/var/lib/docker/overlay2/8168d858a6a8fcb7de08ca96245535c210935f83890ab4b84c566e361e79face/diff:/var/lib/docker/overlay2/245dcb37f8e6d95006dd1074d5e25227c781d2f485a258a23f4bedb4d4ef67c6/diff:/var/lib/docker/overlay2/778070e6673819923ccfa997d584b2e0d00edda1a13368c68555fe443c483d2c/diff:/var/lib/docker/overlay2/9aab795c6fab20d3f031b27d7544ee574d2d67d1d02a3fe385ab7660b6407047/diff:/var/lib/docker/overlay2/ef6a6cc4aa83a8aa6538fac9348ef1b7dbd71bab55b6d9dbdcb30980ecb4fc5b/diff:/var/lib/docker/overlay2/493fff7a769efd71ed760406b5cda642c0d98071dbeb9fd347eb1fe6759573eb/diff:/var/lib/docker/overlay2/c3dd55bf097f1405b5919e2dd57acbdb1c8f76341c4479252c4724b30c996846/diff:/var/lib/docker/overlay2/de5792ecef047b49c131d27d69c52b9a1fa8ee3cb74cc9ab8d877a896208b8e3/diff:/var/lib/docker/overlay2/25fe0b4329a4fde5f5f1788ee69c846d5c20b727db56aa47c02d4ee3f739c98c/diff",
                "MergedDir": "/var/lib/docker/overlay2/d8eaf63624b1cb008058e7e2cd0c9b8840ff314d41ce0b6c5ec0eada0eae4ef5/merged",
                "UpperDir": "/var/lib/docker/overlay2/d8eaf63624b1cb008058e7e2cd0c9b8840ff314d41ce0b6c5ec0eada0eae4ef5/diff",
                "WorkDir": "/var/lib/docker/overlay2/d8eaf63624b1cb008058e7e2cd0c9b8840ff314d41ce0b6c5ec0eada0eae4ef5/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:aa5968d388b8652cd305e0e037751228967839d83d0cafbde5debf0b092e7c42",
                "sha256:8d19537dd9e29749b0b1da29272e1bbbde1e7d12fcf65190c860776773183455",
                "sha256:a58e8df63d367ec85a9752a84900d35534a40780df4ee1d2b5607db4a477a796",
                "sha256:ec9c9164365e287d5d61ad77050f0f39cc92104645f9d61decb4403a2762f4cc",
                "sha256:88da39ab8318a7459850ae19b2c9089d0bdfdbd96316aba30c0d18212a32a607",
                "sha256:940cf5eed4b17403b725275cce9087ef06033170155a7c0baa7d1b071a3ef34f",
                "sha256:123f30f27f8d8b32824eebdd747e9c86169fef732f614d61eb319c6557153ba5",
                "sha256:dcd63e2e87ac4223042271cbdd33975d80fe2c71e8dc69d63f9e8ed3e1a2061a",
                "sha256:c6869770c7df43e093cce83c2d960bdb785c9b1991b606ec2c117397f812f282",
                "sha256:a83a121f759b489dcbe0b38e1d3b7bf62ec8a9e3f4346cf13fb372cedb590536",
                "sha256:7f67d6b735b7ea16af592be59ee1e025b37c106b5f7bc3b53bfe1742a6513fe1",
                "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
                "sha256:d77e0b169340e20ee59e568a454818019b2033031c583361c50004b92272e5ce",
                "sha256:8b809688f105a8adf736d81f95dff802a7cf825ba2889c3f8922ae5e0ce4c759"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

Summary

Docker image with tag latest on version 9.0.3 is not able to check PHP 8.1 or 8.2 features syntaxes without error.

Expected behaviour

Be able to lint files with PHP 8.1 or 8.2 syntax without error.

Actual behaviour

With PHP 8.1 feature Enums

// php-8.1_syntax.php
enum Suit {
    case Clubs;
    case Diamonds;
    case Hearts;
    case Spades;
}

Running command :

docker run --rm -it -v "${PWD}":/workdir -w /workdir overtrue/phplint:latest tests/fixtures/php-8.1_syntax.php

Prints following output
docker-v9 0 3-php81lint

With PHP 8.2 feature Type System

// php-8.2_syntax.php
function alwaysReturnsFalse(): false {}

Running command :

docker run --rm -it -v "${PWD}":/workdir -w /workdir overtrue/phplint:latest tests/fixtures/php-8.2_syntax.php

Prints following output
docker-v9 0 3-php82lint

Credits

Thanks to @ghnp5 for bringing this to my attention on issue report #179

Only one Docker image is necessary to check all PHP 8 features. BTW, the current build workflow use PHP 8.0 as base.
This is origin of this issue.

You've also perharps noticed that action of set -ex in https://github.com/overtrue/phplint/blob/9.0.3/entrypoint.sh#L3 produce extra output that is not really necessary in production condition.

So I'll apply a little change to enable it by -e APP_DEBUG=true on docker run command (for debugging purpose only).
Default behaviour (without specify it) will act as if we specify -e APP_DEBUG=false : that means do not print extra shell script info.

See commit 0d36c3a

This issue is only related to Docker distribution so no more necessary to publish a new version 9.0.4

First image that solve it has Digest sha256:fbd2816cea52f98ad38ff3d4ceb8e0054df84cc7c523f1031c4acc189a17dc3f

Run examples:

docker run --rm -it -v "${PWD}":/workdir -w /workdir overtrue/phplint:latest tests/fixtures/php-8.2_syntax.php
docker run --rm -it -v "${PWD}":/workdir -w /workdir overtrue/phplint:latest tests/fixtures/php-8.1_syntax.php
docker run --rm -it -v "${PWD}":/workdir -w /workdir -e APP_DEBUG=true overtrue/phplint:latest tests/fixtures/php-8.1_syntax.php

Here is a screenshot of what it look like when -e APP_DEBUG=true is enabled

81-results

commented

@llaville About this:

Only one Docker image is necessary to check all PHP 8 features. BTW, the current build workflow use PHP 8.0 as base.
This is origin of this issue.

I believe it would be good to have a choice to choose the exact version, like I suggested in #179

For example, we could have a project that is on PHP 8.0, and hasn't upgraded production to use PHP 8.2 yet.

If a developer starts using an enum, and has PHP 8.1 installed on their machine, all works fine, but then it goes to Production, and it crashes, because the Production server only has PHP 8.0 installed.

If we had a phplint docker image with "8.0" as the tag, at least we would find that the enum can't be used at the moment.

Thanks for your fix above! :)

@ghnp5 I know your point of view, but I'm 👎 to manage multiple docker images. Let me explain my point of view.

If you really want to know what your source code used as PHP features, and learn about minimum requirements, I suggest to have a look on my project https://github.com/llaville/php-compatinfo (no PHAR or Docker distributions yet, but it will come)

And If you want to lint only files to check if your platform support them, I recommend to use the PHAR distribution of PHPLint rather than Docker image.
PHAR version use the same runtime of platform run !

@ghnp5 Related to this subject, here is how we can check PHP syntax by following PHP runtime defined with PHAR alternative on a GitHub Actions Workflow => #181 (comment)