diff --git a/.gitattributes b/.gitattributes index e0e6b91774b..0e90da01c6a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,6 +13,9 @@ /benchmark.sh export-ignore /box.json.dist export-ignore /dev-tools/ export-ignore +/docker/ export-ignore +/docker-compose.yaml export-ignore +/docker-compose.override.yaml.dist export-ignore /phpmd.xml export-ignore /phpstan.neon export-ignore /phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index b66feada4ca..1acd5822c1e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /.phpunit.result.cache /box.json /composer.lock +/docker-compose.override.yaml /php-cs-fixer.phar /phpunit.xml /vendor/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 695d56112e3..a3eb381f275 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,52 @@ Symfony projects for instance). * Check if tests pass: `vendor/bin/phpunit`. * Fix project itself: `php php-cs-fixer fix`. +## Working With Docker + +This project provides a Docker setup that allows working on it using any of the supported PHP versions. + +To use it, you first need to install: + + * [Docker](https://docs.docker.com/get-docker/) + * [Docker Compose](https://docs.docker.com/compose/install/) + +Make sure the versions installed support [Compose file format 3.8](https://docs.docker.com/compose/compose-file/). + +Next, copy [`docker-compose.override.yaml.dist`](./docker-compose.override.yaml.dist) to `docker-compose.override.yaml` +and edit it to your needs. The relevant parameters that might require some tweaking have comments to help you. + +You can then build the images: + +```console +$ docker-compose build --parallel +``` + +Now you can run commands needed to work on the project. For example, say you want to run PHPUnit tests on PHP 7.4: + +```console +$ docker-compose run php-7.4 vendor/bin/phpunit +``` + +Sometimes it can be more convenient to have a shell inside the container: + +```console +$ docker-compose run php-7.4 sh +/app $ vendor/bin/phpunit +``` + +The images come with an [`xdebug` script](github.com/julienfalque/xdebug/) that allows running any PHP command with +Xdebug enabled to help debug problems. + +```console +docker-compose run php-7.4 xdebug vendor/bin/phpunit +``` + +If you're using PhpStorm, you need to create a [server](https://www.jetbrains.com/help/phpstorm/servers.html) with a +name that matches the `PHP_IDE_CONFIG` environment variable defined in the Docker Compose configuration files, which is +`php-cs-fixer` by default. + +All images use port 9003 for debug connections. + ## Opening a [Pull Request](https://help.github.com/articles/about-pull-requests/) You can do some things to increase the chance that your Pull Request is accepted the first time: diff --git a/docker-compose.override.yaml.dist b/docker-compose.override.yaml.dist new file mode 100644 index 00000000000..a593f888536 --- /dev/null +++ b/docker-compose.override.yaml.dist @@ -0,0 +1,25 @@ +version: '3.8' + +services: + php-5.6: &php + build: + args: + DOCKER_USER_ID: 1000 # replace with your user id (most likely 1000) + DOCKER_GROUP_ID: 1000 # replace with your group id (most likely 1000) + user: 1000:1000 # replace with your user and group ids (most likely 1000:1000) + extra_hosts: + # Required for Docker Linux until natively supported. + # See https://github.com/docker/for-linux/issues/264 + host.docker.internal: 172.17.0.1 + php-7.0: + <<: *php + php-7.1: + <<: *php + php-7.2: + <<: *php + php-7.3: + <<: *php + php-7.4: + <<: *php + php-8.0: + <<: *php diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000000..b16e3ebf0d0 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + php-5.6: &php + build: docker/php-5.6 + working_dir: /app + volumes: + - .:/app + environment: + PHP_IDE_CONFIG: serverName=php-cs-fixer + PHP_CS_FIXER_ALLOW_XDEBUG: 1 + php-7.0: + <<: *php + build: docker/php-7.0 + php-7.1: + <<: *php + build: docker/php-7.1 + php-7.2: + <<: *php + build: docker/php-7.2 + php-7.3: + <<: *php + build: docker/php-7.3 + php-7.4: + <<: *php + build: docker/php-7.4 + php-8.0: + <<: *php + build: docker/php-8.0 diff --git a/docker/php-5.6/Dockerfile b/docker/php-5.6/Dockerfile new file mode 100644 index 00000000000..7c194f0173e --- /dev/null +++ b/docker/php-5.6/Dockerfile @@ -0,0 +1,27 @@ +FROM php:5.6-cli-alpine3.8 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-2.5.5 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v1.1.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-5.6/xdebug.ini b/docker/php-5.6/xdebug.ini new file mode 100644 index 00000000000..8ea67c8bebd --- /dev/null +++ b/docker/php-5.6/xdebug.ini @@ -0,0 +1,5 @@ +;zend_extension=xdebug.so +xdebug.remote_autostart=1 +xdebug.remote_enable=1 +xdebug.remote_host=host.docker.internal +xdebug.remote_port=9003 diff --git a/docker/php-7.0/Dockerfile b/docker/php-7.0/Dockerfile new file mode 100644 index 00000000000..b0b82ecd488 --- /dev/null +++ b/docker/php-7.0/Dockerfile @@ -0,0 +1,27 @@ +FROM php:7.0-cli-alpine3.7 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-2.7.2 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v1.1.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-7.0/xdebug.ini b/docker/php-7.0/xdebug.ini new file mode 100644 index 00000000000..8ea67c8bebd --- /dev/null +++ b/docker/php-7.0/xdebug.ini @@ -0,0 +1,5 @@ +;zend_extension=xdebug.so +xdebug.remote_autostart=1 +xdebug.remote_enable=1 +xdebug.remote_host=host.docker.internal +xdebug.remote_port=9003 diff --git a/docker/php-7.1/Dockerfile b/docker/php-7.1/Dockerfile new file mode 100644 index 00000000000..326738295ec --- /dev/null +++ b/docker/php-7.1/Dockerfile @@ -0,0 +1,27 @@ +FROM php:7.1-cli-alpine3.10 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-2.9.8 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v1.1.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-7.1/xdebug.ini b/docker/php-7.1/xdebug.ini new file mode 100644 index 00000000000..8ea67c8bebd --- /dev/null +++ b/docker/php-7.1/xdebug.ini @@ -0,0 +1,5 @@ +;zend_extension=xdebug.so +xdebug.remote_autostart=1 +xdebug.remote_enable=1 +xdebug.remote_host=host.docker.internal +xdebug.remote_port=9003 diff --git a/docker/php-7.2/Dockerfile b/docker/php-7.2/Dockerfile new file mode 100644 index 00000000000..8d3672c3cae --- /dev/null +++ b/docker/php-7.2/Dockerfile @@ -0,0 +1,27 @@ +FROM php:7.2-cli-alpine3.12 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-2.9.8 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v2.0.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-7.2/xdebug.ini b/docker/php-7.2/xdebug.ini new file mode 100644 index 00000000000..8ea67c8bebd --- /dev/null +++ b/docker/php-7.2/xdebug.ini @@ -0,0 +1,5 @@ +;zend_extension=xdebug.so +xdebug.remote_autostart=1 +xdebug.remote_enable=1 +xdebug.remote_host=host.docker.internal +xdebug.remote_port=9003 diff --git a/docker/php-7.3/Dockerfile b/docker/php-7.3/Dockerfile new file mode 100644 index 00000000000..512da58aa88 --- /dev/null +++ b/docker/php-7.3/Dockerfile @@ -0,0 +1,27 @@ +FROM php:7.3-cli-alpine3.13 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-3.0.1 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v2.0.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-7.3/xdebug.ini b/docker/php-7.3/xdebug.ini new file mode 100644 index 00000000000..cd4b802e88a --- /dev/null +++ b/docker/php-7.3/xdebug.ini @@ -0,0 +1,4 @@ +;zend_extension=xdebug.so +xdebug.client_host=host.docker.internal +xdebug.mode=debug +xdebug.start_with_request=yes diff --git a/docker/php-7.4/Dockerfile b/docker/php-7.4/Dockerfile new file mode 100644 index 00000000000..e6a4ab7aa62 --- /dev/null +++ b/docker/php-7.4/Dockerfile @@ -0,0 +1,27 @@ +FROM php:7.4-cli-alpine3.13 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-3.0.1 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v2.0.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-7.4/xdebug.ini b/docker/php-7.4/xdebug.ini new file mode 100644 index 00000000000..cd4b802e88a --- /dev/null +++ b/docker/php-7.4/xdebug.ini @@ -0,0 +1,4 @@ +;zend_extension=xdebug.so +xdebug.client_host=host.docker.internal +xdebug.mode=debug +xdebug.start_with_request=yes diff --git a/docker/php-8.0/Dockerfile b/docker/php-8.0/Dockerfile new file mode 100644 index 00000000000..e49c999a5dc --- /dev/null +++ b/docker/php-8.0/Dockerfile @@ -0,0 +1,27 @@ +FROM php:8.0-cli-alpine3.13 + +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID + +RUN if ! getent group "${DOCKER_GROUP_ID}" > /dev/null; \ + then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ + fi \ + && if ! getent passwd "${DOCKER_USER_ID}" > /dev/null; \ + then adduser -S -u "${DOCKER_USER_ID}" -G "$(getent group "${DOCKER_GROUP_ID}" | awk -F: '{printf $1}')" dev; \ + fi \ + && apk add --no-cache git libxml2-dev openssh-client \ + && apk add --no-cache --virtual .build-deps autoconf g++ make \ + # xdebug + && pecl install xdebug-3.0.1 \ + && docker-php-ext-enable xdebug \ + # composer + && curl --output composer-setup.php https://getcomposer.org/installer \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && rm composer-setup.php \ + # xdebug command + && curl --location --output /usr/local/bin/xdebug https://github.com/julienfalque/xdebug/releases/download/v2.0.0/xdebug \ + && chmod +x /usr/local/bin/xdebug \ + # clean up + && apk del .build-deps + +COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini diff --git a/docker/php-8.0/xdebug.ini b/docker/php-8.0/xdebug.ini new file mode 100644 index 00000000000..cd4b802e88a --- /dev/null +++ b/docker/php-8.0/xdebug.ini @@ -0,0 +1,4 @@ +;zend_extension=xdebug.so +xdebug.client_host=host.docker.internal +xdebug.mode=debug +xdebug.start_with_request=yes diff --git a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php index 9ea690e7015..fe68614fa46 100644 --- a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php +++ b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php @@ -97,7 +97,7 @@ protected function createConfigurationDefinition() protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $tokensAnalyzer = new TokensAnalyzer($tokens); - $propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT]; + $propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; foreach (array_reverse($tokensAnalyzer->getClassyElements(), true) as $index => $element) { if (!\in_array($element['type'], $this->configuration['elements'], true)) { diff --git a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php index 298c4580153..ae9ca1defe2 100644 --- a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php +++ b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php @@ -827,4 +827,27 @@ public function provideFix74Cases() 'doTest($expected, $input); + } + + public function provideFix80Cases() + { + yield [ + '