Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Jan 18, 2021
2 parents 4aee7b6 + 35997b4 commit 817e7dd
Show file tree
Hide file tree
Showing 21 changed files with 349 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.phpunit.result.cache
/box.json
/composer.lock
/docker-compose.override.yaml
/php-cs-fixer.phar
/phpunit.xml
/vendor/
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions docker-compose.override.yaml.dist
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docker/php-5.6/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions docker/php-5.6/xdebug.ini
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docker/php-7.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions docker/php-7.0/xdebug.ini
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docker/php-7.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions docker/php-7.1/xdebug.ini
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docker/php-7.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions docker/php-7.2/xdebug.ini
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docker/php-7.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/php-7.3/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;zend_extension=xdebug.so
xdebug.client_host=host.docker.internal
xdebug.mode=debug
xdebug.start_with_request=yes
27 changes: 27 additions & 0 deletions docker/php-7.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/php-7.4/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;zend_extension=xdebug.so
xdebug.client_host=host.docker.internal
xdebug.mode=debug
xdebug.start_with_request=yes
27 changes: 27 additions & 0 deletions docker/php-8.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/php-8.0/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;zend_extension=xdebug.so
xdebug.client_host=host.docker.internal
xdebug.mode=debug
xdebug.start_with_request=yes
2 changes: 1 addition & 1 deletion src/Fixer/ClassNotation/VisibilityRequiredFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,27 @@ public function provideFix74Cases()
'<?php class Foo { static public ?array $foo; }',
];
}

/**
* @param string $expected
* @param null|string $input
*
* @requires PHP 8.0
* @dataProvider provideFix80Cases
*/
public function testFix80($expected, $input = null)
{
$this->doTest($expected, $input);
}

public function provideFix80Cases()
{
yield [
'<?php class Foo { private int|float|null $foo; }',
];

yield [
'<?php class Foo { private int | /* or empty */ null $foo; }',
];
}
}

0 comments on commit 817e7dd

Please sign in to comment.