From 7dd3a773a144fee6b7f4f7bba584a7e2ead54773 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 15 Feb 2023 07:17:20 +0000 Subject: [PATCH 01/28] fix and upgrade documentation --- docs/architecture/README.md | 14 ++++++++++++++ docs/architecture/extension.md | 4 ++-- docs/index.md | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 docs/architecture/README.md diff --git a/docs/architecture/README.md b/docs/architecture/README.md new file mode 100644 index 00000000..266ff1bf --- /dev/null +++ b/docs/architecture/README.md @@ -0,0 +1,14 @@ + +# Architecture's Guide + +This guide is dedicated to all PHP developers that want to learn more about each PHPLint components. + +## Table Of Contents + +- [Cache](cache.md#cache) to learn how PHPLint is able to improve speed analysis on multiple runs +- [Configuration](configuration.md#configuration) to learn how PHPLint options can customize your checks +- [Event-Driven](event.md#event-driven-architecture-on-wikipediaeda) to learn more about how to extend PHPLint features +- [Extension](extension.md#extension) to learn more about how to extend PHPLint features +- [Finder](finder.md#finder) to learn how PHPLint find files to check +- [Output](output.md#output-formats) to learn how PHPLint can customize results output +- [Process](process.md#process) to learn how PHPLint is able to run multiple processes in parallel diff --git a/docs/architecture/extension.md b/docs/architecture/extension.md index e349fc64..2c87a609 100644 --- a/docs/architecture/extension.md +++ b/docs/architecture/extension.md @@ -71,8 +71,8 @@ use Overtrue\PHPLint\Extension\OutputFormat; $extensions = [ new OutputFormat([ - OptionDefinition::OPTION_JSON_FILE, - OptionDefinition::OPTION_JUNIT_FILE, + OptionDefinition::LOG_JSON, + OptionDefinition::LOG_JUNIT, ]) ]; diff --git a/docs/index.md b/docs/index.md index 98ba774b..55915b1d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -13,6 +13,12 @@ with following command: The PHPLint is a command line tool that can speed up linting of php files by running several lint processes at once. +## Architecture + +> As a developer you want to learn more about PHPLint architecture!. + +See [Architecture's Guide](architecture/README.md) + ## Usage 1. [Console CLI](#console-cli) From 1f56c6bb222bd351d3a51098fba018c050b100cd Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 15 Feb 2023 07:47:51 +0000 Subject: [PATCH 02/28] upgrade documentation / best compromise between GitHub Online and Material for MkDocs readability --- README.md | 1 + docs/{index.md => README.md} | 0 docs/architecture/README.md | 37 ++++++++++++++++++++++++++---------- mkdocs.yml | 11 ++--------- 4 files changed, 30 insertions(+), 19 deletions(-) rename docs/{index.md => README.md} (100%) diff --git a/README.md b/README.md index 5423a10c..9e9bc83c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ with lot of improvement, full documentation, and full unit code tested. 1. [Configuration](docs/configuration.md#configuration) 1. [Upgrading](docs/upgrading.md#upgrading) 1. [Contributing](docs/contributing.md#contributing) +1. [Architecture](docs/architecture/README.md#architecture) ## :heart: Sponsor me diff --git a/docs/index.md b/docs/README.md similarity index 100% rename from docs/index.md rename to docs/README.md diff --git a/docs/architecture/README.md b/docs/architecture/README.md index 266ff1bf..6e22937a 100644 --- a/docs/architecture/README.md +++ b/docs/architecture/README.md @@ -1,14 +1,31 @@ - -# Architecture's Guide +# Architecture This guide is dedicated to all PHP developers that want to learn more about each PHPLint components. -## Table Of Contents +## [Cache](cache.md#cache) + +To learn how PHPLint is able to improve speed analysis on multiple runs. + +## [Configuration](configuration.md#configuration) + +To learn how PHPLint options can customize your checks. + +## [Event-Driven](event.md#event-driven-architecture-on-wikipediaeda) + +To learn more about how to extend PHPLint features. + +## [Extension](extension.md#extension) + +To learn more about how to extend PHPLint features. + +## [Finder](finder.md#finder) + +To learn how PHPLint find files to check. + +## [Output](output.md#output-formats) + +To learn how PHPLint can customize results output. + +## [Process](process.md#process) -- [Cache](cache.md#cache) to learn how PHPLint is able to improve speed analysis on multiple runs -- [Configuration](configuration.md#configuration) to learn how PHPLint options can customize your checks -- [Event-Driven](event.md#event-driven-architecture-on-wikipediaeda) to learn more about how to extend PHPLint features -- [Extension](extension.md#extension) to learn more about how to extend PHPLint features -- [Finder](finder.md#finder) to learn how PHPLint find files to check -- [Output](output.md#output-formats) to learn how PHPLint can customize results output -- [Process](process.md#process) to learn how PHPLint is able to run multiple processes in parallel +To learn how PHPLint is able to run multiple processes in parallel. diff --git a/mkdocs.yml b/mkdocs.yml index 89e90506..5031fe7a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -27,16 +27,9 @@ markdown_extensions: - pymdownx.highlight # https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/#highlight - pymdownx.superfences # https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/#superfences nav: - - "Home": index.md + - "Home": README.md - "Installation": installation.md - "Upgrading": upgrading.md - "Configuration": configuration.md - - "Architecture": - - "Event-Driven": architecture/event.md - - "Extension": architecture/extension.md - - "Output (formats)": architecture/output.md - - "Process": architecture/process.md - - "Cache": architecture/cache.md - - "Finder": architecture/finder.md - - "Configuration": architecture/configuration.md + - "Architecture": architecture/README.md - "Contributing": contributing.md From 73c12ddcd5f093d15544f3c82bd949ef593f3cc7 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 15 Feb 2023 07:52:54 +0000 Subject: [PATCH 03/28] fix broken badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e9bc83c..f931bf29 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

`phplint` is a tool that can speed up linting of php files by running several lint processes at once.

-[![Release Status](https://github.com/overtrue/phplint/actions/workflows/build-phar.yml/badge.svg)](https://github.com/overtrue/phplint/actions/workflows/build-phar.yml) +[![Release Status](https://github.com/overtrue/phplint/actions/workflows/release.yml/badge.svg)](https://github.com/overtrue/phplint/actions/workflows/release.yml) [![Latest Stable Version](https://img.shields.io/packagist/v/overtrue/phplint)](https://packagist.org/packages/overtrue/phplint) [![Total Downloads](https://poser.pugx.org/overtrue/phplint/downloads.svg)](https://packagist.org/packages/overtrue/phplint) [![License](https://poser.pugx.org/overtrue/phplint/license.svg)](https://packagist.org/packages/overtrue/phplint) From 76dfd0138b33d9a79441c677102b556b64321746 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 15 Feb 2023 08:15:37 +0000 Subject: [PATCH 04/28] improve Quality process (PHP-CS-Fixer will also check examples folder) --- .php-cs-fixer.dist.php | 2 +- examples/no-yaml-configuration.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 9bacd6e0..784e7ed5 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -32,6 +32,6 @@ PhpCsFixer\Finder::create() ->exclude('vendor') ->notPath('fixtures/syntax_error.php') - ->in([__DIR__.'/src/', __DIR__.'/tests/']) + ->in([__DIR__.'/src/', __DIR__.'/examples', __DIR__.'/tests/']) ) ; diff --git a/examples/no-yaml-configuration.php b/examples/no-yaml-configuration.php index 8f1447fb..99f5573d 100644 --- a/examples/no-yaml-configuration.php +++ b/examples/no-yaml-configuration.php @@ -1,5 +1,14 @@ Date: Fri, 17 Feb 2023 12:48:22 +0000 Subject: [PATCH 05/28] fix broken link following previous commit 1f56c6b --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f931bf29..01d20af8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ with lot of improvement, full documentation, and full unit code tested. 1. [Docker](docs/installation.md#docker) 1. [Phive](docs/installation.md#phive) 1. [Composer](docs/installation.md#composer) -1. [Usage](docs/index.md#usage) +1. [Usage](docs/README.md#usage) 1. [Configuration](docs/configuration.md#configuration) 1. [Upgrading](docs/upgrading.md#upgrading) 1. [Contributing](docs/contributing.md#contributing) From 0d36c3a1b02b2d7f608e921745be4617b15d784e Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Fri, 17 Feb 2023 14:47:42 +0000 Subject: [PATCH 06/28] corresponding to comment https://github.com/overtrue/phplint/issues/180#issuecomment-1434748125 --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0aada501..f983c075 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/sh -l -set -ex +[ "$APP_DEBUG" == 'true' ] && set -x +set -e if [ ! -z "$INPUT_PATH" ]; then /root/.composer/vendor/bin/phplint $INPUT_PATH $INPUT_OPTIONS From 1a94dae04e52c11a982b40baa207fc4ea48d1e66 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Fri, 17 Feb 2023 14:50:05 +0000 Subject: [PATCH 07/28] fix issue #180 --- Dockerfile | 8 +++----- tests/fixtures/php-8.1_syntax.php | 18 ++++++++++++++++++ tests/fixtures/php-8.2_syntax.php | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/php-8.1_syntax.php create mode 100644 tests/fixtures/php-8.2_syntax.php diff --git a/Dockerfile b/Dockerfile index c421bff4..727937e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,7 @@ -ARG VERSION=8.0 +FROM composer:2.5 AS build +RUN composer global require overtrue/phplint ^9.0 -FROM composer:2.0 AS build -RUN composer global require overtrue/phplint 9.0.x-dev - -FROM php:${VERSION}-cli-alpine +FROM php:8.2-cli-alpine COPY --from=build /tmp/vendor /root/.composer/vendor COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh diff --git a/tests/fixtures/php-8.1_syntax.php b/tests/fixtures/php-8.1_syntax.php new file mode 100644 index 00000000..7ef9146f --- /dev/null +++ b/tests/fixtures/php-8.1_syntax.php @@ -0,0 +1,18 @@ + Date: Sun, 19 Feb 2023 07:42:52 +0000 Subject: [PATCH 08/28] split usage doc into multiple chapters --- docs/README.md | 175 +-------------------------------- docs/usage/README.md | 8 ++ docs/usage/console.md | 59 +++++++++++ docs/usage/docker.md | 10 ++ docs/usage/gitlab-ci.md | 10 ++ docs/usage/gituhb-actions.md | 8 ++ docs/usage/other-ci.md | 7 ++ docs/usage/programmatically.md | 66 +++++++++++++ mkdocs.yml | 1 + 9 files changed, 172 insertions(+), 172 deletions(-) create mode 100644 docs/usage/README.md create mode 100644 docs/usage/console.md create mode 100644 docs/usage/docker.md create mode 100644 docs/usage/gitlab-ci.md create mode 100644 docs/usage/gituhb-actions.md create mode 100644 docs/usage/other-ci.md create mode 100644 docs/usage/programmatically.md diff --git a/docs/README.md b/docs/README.md index 55915b1d..16491191 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,178 +21,9 @@ See [Architecture's Guide](architecture/README.md) ## Usage -1. [Console CLI](#console-cli) -1. [Docker CLI](#docker-cli) -1. [GitHub Actions](#github-actions) -1. [GitLab CI](#gitlab-ci) -1. [Other CI Pipelines](#other-ci-pipelines) -2. [Programmatically](#programmatically) - -### Console CLI - -Linting PHP source files should be as simple as running `phplint` with one or more source paths (no config required!). -It will however assume some defaults that you might want to change. - -PHPLint will by default be looking in order for the file `.phplint.yml` in the current working directory. -You can use another filename by option: `--configuration=FILENAME` or `-c FILENAME`. - -A basic configuration could be for example: - -```yaml -path: ./src -jobs: 10 -extensions: - - php -exclude: - - vendor -warning: true -memory-limit: -1 -no-cache: true -``` - -> If you want to ignore the configuration file directives, you should specify option `--no-configuration`. - -You can then find more advanced configuration settings in [the configuration documentation](configuration.md). -For more information on which options are available, you can run: `phplint --help` - -```text -Description: - Files syntax check only - -Usage: - lint [options] [--] [...] - -Arguments: - path Path to file or directory to lint (default: working directory) - -Options: - --exclude=EXCLUDE Path to file or directory to exclude from linting (multiple values allowed) - --extensions=EXTENSIONS Check only files with selected extensions (multiple values allowed) - -j, --jobs=JOBS Number of paralleled jobs to run - -c, --configuration=CONFIGURATION Read configuration from config file [default: ".phplint.yml"] - --no-configuration Ignore default configuration file (.phplint.yml) - --cache=CACHE Path to the cache directory - --no-cache Ignore cached data - -p, --progress=PROGRESS Show the progress output - --no-progress Hide the progress output - --log-json[=LOG-JSON] Log scan results in JSON format to file (default: standard output) - --log-junit[=LOG-JUNIT] Log scan results in JUnit XML format to file (default: standard output) - -w, --warning Also show warnings - --memory-limit=MEMORY-LIMIT Memory limit for analysis - --ignore-exit-code Ignore exit codes so there are no "failure" exit code even when no files processed - -h, --help Display help for the given command. When no command is given display help for the lint command - -q, --quiet Do not output any message - -V, --version Display this application version - --ansi|--no-ansi Force (or disable --no-ansi) ANSI output - -n, --no-interaction Do not ask any interactive question - -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug -``` - -### Docker CLI - -```shell -docker run --rm -t -v "${PWD}":/workdir overtrue/phplint:latest ./ --exclude=vendor --no-configuration --no-cache -``` - -> Please mount your source code to `/workdir` in the container. - -> Be carefully when you use the cache subsystem. Don't forget to specify `-u "$(id -u):$(id -g)"` arguments on `docker run` command, -otherwise cache files (into `.phplint.cache` directory by default) will be created with `root` account. - -### GitHub Actions - -```yaml -uses: overtrue/phplint@main -with: - path: . - options: --exclude=vendor -``` - -### GitLab CI - -```yaml -code-quality:lint-php: - image: overtrue/phplint:latest - variables: - INPUT_PATH: "./" - INPUT_OPTIONS: "-c .phplint.yml" - script: echo '' #prevents ci yml parse error -``` - -### Other CI Pipelines - -Run this command using `overtrue/phplint:latest` Docker image: - -```shell -/root/.composer/vendor/bin/phplint ./ --exclude=vendor -``` - -### Programmatically - -```php -use Overtrue\PHPLint\Command\LintCommand; -use Overtrue\PHPLint\Configuration\ConsoleOptionsResolver; -use Overtrue\PHPLint\Event\EventDispatcher; -use Overtrue\PHPLint\Finder; -use Overtrue\PHPLint\Linter; -use Symfony\Component\Console\Input\ArrayInput; - -$dispatcher = new EventDispatcher([]); - -$arguments = [ - 'path' => [__DIR__ . '/src', __DIR__ . '/tests'], - '--no-configuration' => true, - '--no-cache' => true, - '--exclude' => ['vendor'], - '--extensions' => ['php'], - '--warning' => true, -]; -$command = new LintCommand($dispatcher); -$definition = $command->getDefinition(); -$input = new ArrayInput($arguments, $definition); - -$configResolver = new ConsoleOptionsResolver($input); - -$finder = new Finder($configResolver); - -$linter = new Linter($configResolver, $dispatcher); - -$results = $linter->lintFiles($finder->getFiles()); - -var_dump($results->getErrors()); -/* - array(1) { - ["/absolute/path/to/tests/fixtures/syntax_error.php"]=> - array(4) { - ["absolute_file"]=> - string(62) "/absolute/path/to/tests/fixtures/syntax_error.php" - ["relative_file"]=> - string(25) "fixtures/syntax_error.php" - ["error"]=> - string(32) "unexpected end of file in line 4" - ["line"]=> - int(4) - } -} - */ - -var_dump($results->getWarnings()); -/* -array(1) { - ["/absolute/path/to/tests/fixtures/syntax_warning.php"]=> - array(4) { - ["absolute_file"]=> - string(64) "/absolute/path/to/tests/fixtures/syntax_warning.php" - ["relative_file"]=> - string(27) "fixtures/syntax_warning.php" - ["error"]=> - string(97) " declare(encoding=...) ignored because Zend multibyte feature is turned off by settings in line 1" - ["line"]=> - int(1) - } -} - */ -``` +> Learn more about different usages with console, Docker, CI, and programmatically. + +See [Getting-Started's Guide](usage/README.md) to know how to use it. ## Contributing diff --git a/docs/usage/README.md b/docs/usage/README.md new file mode 100644 index 00000000..9343ea0d --- /dev/null +++ b/docs/usage/README.md @@ -0,0 +1,8 @@ +# Usage + +1. [Console CLI](console.md) +1. [Docker CLI](docker.md) +1. [GitHub Actions](gituhb-actions.md) +1. [GitLab CI](gitlab-ci.md) +1. [Other CI Pipelines](other-ci.md) +1. [Programmatically](programmatically.md) diff --git a/docs/usage/console.md b/docs/usage/console.md new file mode 100644 index 00000000..4700d215 --- /dev/null +++ b/docs/usage/console.md @@ -0,0 +1,59 @@ +# Console CLI + +Linting PHP source files should be as simple as running `phplint` with one or more source paths (no config required!). +It will however assume some defaults that you might want to change. + +PHPLint will by default be looking in order for the file `.phplint.yml` in the current working directory. +You can use another filename by option: `--configuration=FILENAME` or `-c FILENAME`. + +A basic configuration could be for example: + +```yaml +path: ./src +jobs: 10 +extensions: + - php +exclude: + - vendor +warning: true +memory-limit: -1 +no-cache: true +``` + +> If you want to ignore the configuration file directives, you should specify option `--no-configuration`. + +You can then find more advanced configuration settings in [the configuration documentation](configuration.md). +For more information on which options are available, you can run: `phplint --help` + +```text +Description: + Files syntax check only + +Usage: + lint [options] [--] [...] + +Arguments: + path Path to file or directory to lint (default: working directory) + +Options: + --exclude=EXCLUDE Path to file or directory to exclude from linting (multiple values allowed) + --extensions=EXTENSIONS Check only files with selected extensions (multiple values allowed) + -j, --jobs=JOBS Number of paralleled jobs to run + -c, --configuration=CONFIGURATION Read configuration from config file [default: ".phplint.yml"] + --no-configuration Ignore default configuration file (.phplint.yml) + --cache=CACHE Path to the cache directory + --no-cache Ignore cached data + -p, --progress=PROGRESS Show the progress output + --no-progress Hide the progress output + --log-json[=LOG-JSON] Log scan results in JSON format to file (default: standard output) + --log-junit[=LOG-JUNIT] Log scan results in JUnit XML format to file (default: standard output) + -w, --warning Also show warnings + --memory-limit=MEMORY-LIMIT Memory limit for analysis + --ignore-exit-code Ignore exit codes so there are no "failure" exit code even when no files processed + -h, --help Display help for the given command. When no command is given display help for the lint command + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi|--no-ansi Force (or disable --no-ansi) ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug +``` diff --git a/docs/usage/docker.md b/docs/usage/docker.md new file mode 100644 index 00000000..d9c7d699 --- /dev/null +++ b/docs/usage/docker.md @@ -0,0 +1,10 @@ +# Docker CLI + +```shell +docker run --rm -t -v "${PWD}":/workdir overtrue/phplint:latest ./ --exclude=vendor --no-configuration --no-cache +``` + +> Please mount your source code to `/workdir` in the container. + +> Be carefully when you use the cache subsystem. Don't forget to specify `-u "$(id -u):$(id -g)"` arguments on `docker run` command, +otherwise cache files (into `.phplint.cache` directory by default) will be created with `root` account. diff --git a/docs/usage/gitlab-ci.md b/docs/usage/gitlab-ci.md new file mode 100644 index 00000000..c54ca19c --- /dev/null +++ b/docs/usage/gitlab-ci.md @@ -0,0 +1,10 @@ +# GitLab CI + +```yaml +code-quality:lint-php: + image: overtrue/phplint:latest + variables: + INPUT_PATH: "./" + INPUT_OPTIONS: "-c .phplint.yml" + script: echo '' #prevents ci yml parse error +``` diff --git a/docs/usage/gituhb-actions.md b/docs/usage/gituhb-actions.md new file mode 100644 index 00000000..1b6e38b9 --- /dev/null +++ b/docs/usage/gituhb-actions.md @@ -0,0 +1,8 @@ +# GitHub Actions + +```yaml +uses: overtrue/phplint@main +with: + path: . + options: --exclude=vendor +``` diff --git a/docs/usage/other-ci.md b/docs/usage/other-ci.md new file mode 100644 index 00000000..9f9fcb08 --- /dev/null +++ b/docs/usage/other-ci.md @@ -0,0 +1,7 @@ +# Other CI Pipelines + +Run this command using `overtrue/phplint:latest` Docker image: + +```shell +/root/.composer/vendor/bin/phplint ./ --exclude=vendor +``` diff --git a/docs/usage/programmatically.md b/docs/usage/programmatically.md new file mode 100644 index 00000000..317e7d5e --- /dev/null +++ b/docs/usage/programmatically.md @@ -0,0 +1,66 @@ +# Programmatically + +```php +use Overtrue\PHPLint\Command\LintCommand; +use Overtrue\PHPLint\Configuration\ConsoleOptionsResolver; +use Overtrue\PHPLint\Event\EventDispatcher; +use Overtrue\PHPLint\Finder; +use Overtrue\PHPLint\Linter; +use Symfony\Component\Console\Input\ArrayInput; + +$dispatcher = new EventDispatcher([]); + +$arguments = [ + 'path' => [__DIR__ . '/src', __DIR__ . '/tests'], + '--no-configuration' => true, + '--no-cache' => true, + '--exclude' => ['vendor'], + '--extensions' => ['php'], + '--warning' => true, +]; +$command = new LintCommand($dispatcher); +$definition = $command->getDefinition(); +$input = new ArrayInput($arguments, $definition); + +$configResolver = new ConsoleOptionsResolver($input); + +$finder = new Finder($configResolver); + +$linter = new Linter($configResolver, $dispatcher); + +$results = $linter->lintFiles($finder->getFiles()); + +var_dump($results->getErrors()); +/* + array(1) { + ["/absolute/path/to/tests/fixtures/syntax_error.php"]=> + array(4) { + ["absolute_file"]=> + string(62) "/absolute/path/to/tests/fixtures/syntax_error.php" + ["relative_file"]=> + string(25) "fixtures/syntax_error.php" + ["error"]=> + string(32) "unexpected end of file in line 4" + ["line"]=> + int(4) + } +} + */ + +var_dump($results->getWarnings()); +/* +array(1) { + ["/absolute/path/to/tests/fixtures/syntax_warning.php"]=> + array(4) { + ["absolute_file"]=> + string(64) "/absolute/path/to/tests/fixtures/syntax_warning.php" + ["relative_file"]=> + string(27) "fixtures/syntax_warning.php" + ["error"]=> + string(97) " declare(encoding=...) ignored because Zend multibyte feature is turned off by settings in line 1" + ["line"]=> + int(1) + } +} + */ +``` diff --git a/mkdocs.yml b/mkdocs.yml index 5031fe7a..499fe1b7 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -29,6 +29,7 @@ markdown_extensions: nav: - "Home": README.md - "Installation": installation.md + - "Usage": usage/README.md - "Upgrading": upgrading.md - "Configuration": configuration.md - "Architecture": architecture/README.md From 108f7133eb82a6f8a3749966152fdeb4ef1e54d8 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 08:04:01 +0000 Subject: [PATCH 09/28] rename file on typo error --- docs/usage/README.md | 2 +- docs/usage/docker.md | 2 ++ docs/usage/{gituhb-actions.md => github-actions.md} | 0 3 files changed, 3 insertions(+), 1 deletion(-) rename docs/usage/{gituhb-actions.md => github-actions.md} (100%) diff --git a/docs/usage/README.md b/docs/usage/README.md index 9343ea0d..6ac5624a 100644 --- a/docs/usage/README.md +++ b/docs/usage/README.md @@ -2,7 +2,7 @@ 1. [Console CLI](console.md) 1. [Docker CLI](docker.md) -1. [GitHub Actions](gituhb-actions.md) +1. [GitHub Actions](github-actions.md) 1. [GitLab CI](gitlab-ci.md) 1. [Other CI Pipelines](other-ci.md) 1. [Programmatically](programmatically.md) diff --git a/docs/usage/docker.md b/docs/usage/docker.md index d9c7d699..0c31fc1a 100644 --- a/docs/usage/docker.md +++ b/docs/usage/docker.md @@ -8,3 +8,5 @@ docker run --rm -t -v "${PWD}":/workdir overtrue/phplint:latest ./ --exclude=ven > Be carefully when you use the cache subsystem. Don't forget to specify `-u "$(id -u):$(id -g)"` arguments on `docker run` command, otherwise cache files (into `.phplint.cache` directory by default) will be created with `root` account. + +**IMPORTANT** : Docker image with `latest` tag use the PHP 8.2 runtime ! diff --git a/docs/usage/gituhb-actions.md b/docs/usage/github-actions.md similarity index 100% rename from docs/usage/gituhb-actions.md rename to docs/usage/github-actions.md From e7a391fec63820d5fb40bcac7263ee00229ffaff Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 08:24:44 +0000 Subject: [PATCH 10/28] update GitHub Actions usage (following @mimmi20 question https://github.com/overtrue/phplint/issues/181) --- docs/usage/github-actions.md | 67 +++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/docs/usage/github-actions.md b/docs/usage/github-actions.md index 1b6e38b9..8ffc4ef5 100644 --- a/docs/usage/github-actions.md +++ b/docs/usage/github-actions.md @@ -1,8 +1,67 @@ # GitHub Actions +Quick start, if you PHP runtime set up is not important for you. + ```yaml -uses: overtrue/phplint@main -with: - path: . - options: --exclude=vendor +jobs: + php-lint: + name: Linting with overtrue/phplint + + runs-on: ubuntu-latest + + steps: + - name: Lint PHP files + + uses: overtrue/phplint@main + with: + path: . + options: --exclude=vendor ``` + +Otherwise, if you want to detect specific PHP features used by scripts depending of your PHP runtime, then use this case. + +```yaml +jobs: + php-lint: + name: "Linting with overtrue/phplint" + + runs-on: "${{ matrix.operating-system }}" + + strategy: + fail-fast: false + + matrix: + operating-system: + - "ubuntu-20.04" + - "ubuntu-22.04" + + php-version: + - "8.1" + - "8.2" + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + repository: overtrue/phplint + + - name: Setup PHP runtime + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + coverage: "none" + + - name: Lint PHP files + run: | + curl -Ls https://github.com/overtrue/phplint/releases/latest/download/phplint.phar -o /usr/local/bin/phplint + chmod +x /usr/local/bin/phplint + /usr/local/bin/phplint -vvv --no-cache +``` + +Follows steps: + +- retrieve source code to check with [actions/checkout](https://github.com/actions/checkout) +- set up the PHP runtime you want to use with [shivammathur/setup-php](https://github.com/shivammathur/setup-php) +- download the latest (or specific) version of the PHAR distribution +- and finally run PHPLint as usual, with a YAML config file or console command options From aabab18ed52e3c06072626a8eed76fe4b82c5160 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 08:28:07 +0000 Subject: [PATCH 11/28] fix typo, and cosmetic --- docs/usage/github-actions.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/usage/github-actions.md b/docs/usage/github-actions.md index 8ffc4ef5..64eee25b 100644 --- a/docs/usage/github-actions.md +++ b/docs/usage/github-actions.md @@ -1,6 +1,8 @@ # GitHub Actions -Quick start, if you PHP runtime set up is not important for you. +## Use case 1 + +Quick start, if your PHP runtime set up is not important for you. ```yaml jobs: @@ -18,6 +20,8 @@ jobs: options: --exclude=vendor ``` +## Use case 2 + Otherwise, if you want to detect specific PHP features used by scripts depending of your PHP runtime, then use this case. ```yaml From 971c42e8c76fefd88ad1e82dc02a3044fbc54ae3 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 09:39:07 +0000 Subject: [PATCH 12/28] add support for PHPUnit 10 --- .../unreleased/Added-20230219-083856.yaml | 3 ++ .github/workflows/lint.yml | 38 ++++++++++++++++--- phpunit-9.xml | 37 ++++++++++++++++++ phpunit.xml | 16 +++----- vendor-bin/phpunit/composer.json | 2 +- 5 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 .changes/unreleased/Added-20230219-083856.yaml create mode 100644 phpunit-9.xml diff --git a/.changes/unreleased/Added-20230219-083856.yaml b/.changes/unreleased/Added-20230219-083856.yaml new file mode 100644 index 00000000..64e4a9ab --- /dev/null +++ b/.changes/unreleased/Added-20230219-083856.yaml @@ -0,0 +1,3 @@ +kind: Added +body: PHPUnit 10 support +time: 2023-02-19T08:38:56.407648037Z diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4b631e8a..ddea58e0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,19 +8,42 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: "${{ matrix.operating-system }}" + + strategy: + fail-fast: false + + matrix: + operating-system: + - "ubuntu-20.04" + - "ubuntu-22.04" + + php-version: + - "8.0" + - "8.1" + - "8.2" + steps: - # Git Checkout name: Checkout code uses: actions/checkout@v3 - - # Setup PHP runtime - name: Setup PHP runtime + - # Setup PHP runtime for PHPUnit 9 tool support + name: Setup PHP runtime for PHPUnit 9 uses: shivammathur/setup-php@v2 + if: ${{ matrix.php-version == '8.0' }} with: - php-version: 8.0 + php-version: "${{ matrix.php-version }}" tools: phpunit:9.6 + - # Setup PHP runtime for PHPUnit 10 tool support + name: Setup PHP runtime for PHPUnit 10 + if: ${{ matrix.php-version != '8.0' }} + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + tools: phpunit + - # Install Composer dependencies name: Install Composer dependencies uses: ramsey/composer-install@v2 @@ -28,5 +51,8 @@ jobs: composer-options: "--prefer-dist --no-scripts" - # Run unit tests - name: Unit tests - run: phpunit + name: Unit tests with PHPUnit 9 + run: phpunit --configuration phpunit-9.xml --testdox --do-not-cache-result + - + name: Unit tests with PHPUnit 10 + run: phpunit --testdox --do-not-cache-result diff --git a/phpunit-9.xml b/phpunit-9.xml new file mode 100644 index 00000000..868c8059 --- /dev/null +++ b/phpunit-9.xml @@ -0,0 +1,37 @@ + + + + + tests/Cache + + + tests/Configuration + + + tests/EndToEnd + + + tests/Finder + + + + + + src + + + diff --git a/phpunit.xml b/phpunit.xml index 868c8059..4ce62f4f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,18 +1,16 @@ + cacheDirectory=".phpunit.cache" + requireCoverageMetadata="true" + beStrictAboutCoverageMetadata="true" +> tests/Cache @@ -27,9 +25,7 @@ tests/Finder - - + src diff --git a/vendor-bin/phpunit/composer.json b/vendor-bin/phpunit/composer.json index 6b4e2784..b4b1b07a 100644 --- a/vendor-bin/phpunit/composer.json +++ b/vendor-bin/phpunit/composer.json @@ -1,5 +1,5 @@ { "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5 || ^10.0" } } From 36585086f1b246e195569033377ae67c6b092e7a Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 09:42:00 +0000 Subject: [PATCH 13/28] fix path for PHPUnit 9 config file --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ddea58e0..2a0ab4ee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -52,7 +52,7 @@ jobs: - # Run unit tests name: Unit tests with PHPUnit 9 - run: phpunit --configuration phpunit-9.xml --testdox --do-not-cache-result + run: phpunit --configuration ./phpunit-9.xml --testdox --do-not-cache-result - name: Unit tests with PHPUnit 10 run: phpunit --testdox --do-not-cache-result From d972f44a3cbd102d4cd7aa1e91dfa2e359b96c5f Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 09:45:03 +0000 Subject: [PATCH 14/28] fix missing conditional execution --- .github/workflows/lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2a0ab4ee..7cb778ac 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -52,7 +52,9 @@ jobs: - # Run unit tests name: Unit tests with PHPUnit 9 + if: ${{ matrix.php-version == '8.0' }} run: phpunit --configuration ./phpunit-9.xml --testdox --do-not-cache-result - name: Unit tests with PHPUnit 10 + if: ${{ matrix.php-version != '8.0' }} run: phpunit --testdox --do-not-cache-result From c2ae11fdb5416fd38d0766a991691074af00c790 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 10:54:02 +0000 Subject: [PATCH 15/28] composer run phpunit shortcuts -- debug option was removed from PHPUnit 10 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9973011e..a005c299 100644 --- a/composer.json +++ b/composer.json @@ -71,9 +71,9 @@ "cghooks": "vendor/bin/cghooks", "check-style": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --using-cache=no --verbose --ansi --diff --dry-run", "fix-style": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --using-cache=no --verbose --ansi", - "tests:unit": "vendor/bin/phpunit --debug --testsuite=cache,configuration,finder", - "tests:e2e": "vendor/bin/phpunit --debug --testsuite=e2e", - "tests:all": "vendor/bin/phpunit --debug", + "tests:unit": "vendor/bin/phpunit --testsuite=cache,configuration,finder", + "tests:e2e": "vendor/bin/phpunit --testsuite=e2e", + "tests:all": "vendor/bin/phpunit", "lint:syntax": "./bin/phplint --ansi" }, "minimum-stability": "dev", From 1f18a955aea51c048c63b5706136af1d5699539f Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 15:08:17 +0000 Subject: [PATCH 16/28] fix issue #182 (use rootless mode now) --- .../unreleased/Fixed-20230219-150315.yaml | 4 ++++ Dockerfile | 22 ++++++++++++++----- docs/usage/docker.md | 3 --- entrypoint.sh | 15 ++++++++----- 4 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 .changes/unreleased/Fixed-20230219-150315.yaml diff --git a/.changes/unreleased/Fixed-20230219-150315.yaml b/.changes/unreleased/Fixed-20230219-150315.yaml new file mode 100644 index 00000000..3efda0a2 --- /dev/null +++ b/.changes/unreleased/Fixed-20230219-150315.yaml @@ -0,0 +1,4 @@ +kind: Fixed +body: '[#182](https://github.com/overtrue/phplint/issues/182) : Docker usage may raise + a permission denied' +time: 2023-02-19T15:03:15.555779829Z diff --git a/Dockerfile b/Dockerfile index 727937e1..f26c63bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,23 @@ -FROM composer:2.5 AS build -RUN composer global require overtrue/phplint ^9.0 +# syntax=docker/dockerfile:1.4 +ARG PHP_VERSION=8.2 +ARG TARGET_DIR="/workdir" + +FROM php:${PHP_VERSION}-cli-alpine -FROM php:8.2-cli-alpine -COPY --from=build /tmp/vendor /root/.composer/vendor COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini -WORKDIR /workdir +# Create a group and user +RUN addgroup appgroup && adduser appuser -D -G appgroup + +# Tell docker that all future commands should run as the appuser user +USER appuser + +# Install Composer v2 then overtrue/phplint package +COPY --from=composer/composer:2-bin /composer /usr/bin/composer +ENV COMPOSER_ALLOW_SUPERUSER 1 +RUN composer global require --no-progress overtrue/phplint ^9.0 + +WORKDIR ${TARGET_DIR} ENTRYPOINT ["/entrypoint.sh"] diff --git a/docs/usage/docker.md b/docs/usage/docker.md index 0c31fc1a..21746c51 100644 --- a/docs/usage/docker.md +++ b/docs/usage/docker.md @@ -6,7 +6,4 @@ docker run --rm -t -v "${PWD}":/workdir overtrue/phplint:latest ./ --exclude=ven > Please mount your source code to `/workdir` in the container. -> Be carefully when you use the cache subsystem. Don't forget to specify `-u "$(id -u):$(id -g)"` arguments on `docker run` command, -otherwise cache files (into `.phplint.cache` directory by default) will be created with `root` account. - **IMPORTANT** : Docker image with `latest` tag use the PHP 8.2 runtime ! diff --git a/entrypoint.sh b/entrypoint.sh index f983c075..b4e3c22d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,13 @@ -#!/bin/sh -l +#!/bin/sh [ "$APP_DEBUG" == 'true' ] && set -x set -e -if [ ! -z "$INPUT_PATH" ]; then - /root/.composer/vendor/bin/phplint $INPUT_PATH $INPUT_OPTIONS -else - sh -c "/root/.composer/vendor/bin/phplint $*" -fi \ No newline at end of file +if [ "$APP_DEBUG" == 'true' ] +then + echo "> You will act as user: $(id -u -n)" + echo "$(composer config --global --list)" + /bin/sh -c "ls -l $(composer config --global home)" +fi + +"$(composer config --global home)/vendor/bin/phplint" $@ From f50c004a86aabd88f7b0a2b684435ca3139ddf1a Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 19 Feb 2023 16:37:19 +0000 Subject: [PATCH 17/28] follows recommendation of GitHub Actions (and do not add WORKDIR directive) --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f26c63bb..7d746abe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ # syntax=docker/dockerfile:1.4 ARG PHP_VERSION=8.2 -ARG TARGET_DIR="/workdir" FROM php:${PHP_VERSION}-cli-alpine @@ -19,5 +18,6 @@ COPY --from=composer/composer:2-bin /composer /usr/bin/composer ENV COMPOSER_ALLOW_SUPERUSER 1 RUN composer global require --no-progress overtrue/phplint ^9.0 -WORKDIR ${TARGET_DIR} +# Following recommendation at https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#workdir + ENTRYPOINT ["/entrypoint.sh"] From 12e8ea1e20daa36d260da1f247dd007a702eaa83 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 08:54:54 +0000 Subject: [PATCH 18/28] ConsoleOutput is no more marked as final class --- .changes/unreleased/Changed-20230222-085355.yaml | 3 +++ src/Output/ConsoleOutput.php | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Changed-20230222-085355.yaml diff --git a/.changes/unreleased/Changed-20230222-085355.yaml b/.changes/unreleased/Changed-20230222-085355.yaml new file mode 100644 index 00000000..e1b7c1a1 --- /dev/null +++ b/.changes/unreleased/Changed-20230222-085355.yaml @@ -0,0 +1,3 @@ +kind: Changed +body: ConsoleOutput is no more final to be able to customize it +time: 2023-02-22T08:53:55.559059951Z diff --git a/src/Output/ConsoleOutput.php b/src/Output/ConsoleOutput.php index bd326c53..91e7df9d 100644 --- a/src/Output/ConsoleOutput.php +++ b/src/Output/ConsoleOutput.php @@ -57,10 +57,12 @@ * @author Laurent Laville * @since Release 9.0.0 */ -final class ConsoleOutput extends BaseConsoleOutput implements OutputInterface +class ConsoleOutput extends BaseConsoleOutput implements OutputInterface { public const MAX_LINE_LENGTH = 120; + public const NO_FILE_TO_LINT = 'Could not find any files to lint'; + private ?ProgressBar $progressBar = null; private int $lineLength; @@ -335,7 +337,7 @@ public function successBlock(int $fileCount): void $style->success($message); } - public function warningBlock(string $message = 'Could not find files to lint'): void + public function warningBlock(string $message = self::NO_FILE_TO_LINT): void { $style = new SymfonyStyle(new ArrayInput([]), $this); $style->warning($message); From 111359b0b1994d47d5e2f99ad41c4357d79c4f6b Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 08:57:57 +0000 Subject: [PATCH 19/28] LinterOutput implement Countable interface --- .../unreleased/Changed-20230222-085614.yaml | 3 +++ src/Output/LinterOutput.php | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Changed-20230222-085614.yaml diff --git a/.changes/unreleased/Changed-20230222-085614.yaml b/.changes/unreleased/Changed-20230222-085614.yaml new file mode 100644 index 00000000..c7fd138a --- /dev/null +++ b/.changes/unreleased/Changed-20230222-085614.yaml @@ -0,0 +1,3 @@ +kind: Changed +body: LinterOutput implement Countable interface +time: 2023-02-22T08:56:14.33882874Z diff --git a/src/Output/LinterOutput.php b/src/Output/LinterOutput.php index bb0984d7..c35c01b0 100644 --- a/src/Output/LinterOutput.php +++ b/src/Output/LinterOutput.php @@ -13,6 +13,8 @@ namespace Overtrue\PHPLint\Output; +use Countable; +use LogicException; use Overtrue\PHPLint\Configuration\Resolver; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Finder\Finder; @@ -27,7 +29,7 @@ * @author Laurent Laville * @since Release 9.0.0 */ -final class LinterOutput +final class LinterOutput implements Countable { private Finder $finder; private array $context; @@ -45,6 +47,11 @@ public function __construct(array $results, Finder $finder) $this->misses = $results['misses'] ?? []; } + public function count(): int + { + return count($this->hits) + count($this->misses); + } + public function getContext(): array { return $this->context; @@ -65,11 +72,17 @@ public function setContext(Resolver $configResolver, float $startTime): void $cacheMisses > 1 ? 'es' : '' ); + try { + $fileCount = count($this->finder); + } catch (LogicException) { + $fileCount = 0; + } + $this->context = [ 'time_usage' => $timeUsage, 'memory_usage' => $memUsage, 'cache_usage' => $cacheUsage, - 'files_count' => count($this->finder), + 'files_count' => $fileCount, 'options_used' => $configResolver->getOptions(), ]; } From 296a2a9aaf71c09e7fe2aeac094c1d070c94a8af Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 09:15:31 +0000 Subject: [PATCH 20/28] make example more readable --- examples/no-yaml-configuration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/no-yaml-configuration.php b/examples/no-yaml-configuration.php index 99f5573d..962a9f75 100644 --- a/examples/no-yaml-configuration.php +++ b/examples/no-yaml-configuration.php @@ -34,11 +34,11 @@ $configResolver = new ConsoleOptionsResolver($input); -$finder = new Finder($configResolver); - +$finder = (new Finder($configResolver))->getFiles(); $linter = new Linter($configResolver, $dispatcher); +$results = $linter->lintFiles($finder); -$results = $linter->lintFiles($finder->getFiles()); +var_dump("Files checked :", count($results)); var_dump("Errors detected :", $results->getErrors()); From 3ce26736ed3fb896f69b3f73da3dba59d1117b17 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 09:40:25 +0000 Subject: [PATCH 21/28] Finder implement JsonSerializable interface --- .changes/unreleased/Changed-20230222-093931.yaml | 3 +++ src/Finder.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Changed-20230222-093931.yaml diff --git a/.changes/unreleased/Changed-20230222-093931.yaml b/.changes/unreleased/Changed-20230222-093931.yaml new file mode 100644 index 00000000..af9a0c01 --- /dev/null +++ b/.changes/unreleased/Changed-20230222-093931.yaml @@ -0,0 +1,3 @@ +kind: Changed +body: Finder implement JsonSerializable interface +time: 2023-02-22T09:39:31.716821987Z diff --git a/src/Finder.php b/src/Finder.php index 6878f189..b290c4a1 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -14,6 +14,7 @@ namespace Overtrue\PHPLint; use ArrayIterator; +use JsonSerializable; use Overtrue\PHPLint\Configuration\OptionDefinition; use Overtrue\PHPLint\Configuration\Resolver; use Symfony\Component\Finder\Finder as SymfonyFinder; @@ -31,7 +32,7 @@ * @author Laurent Laville * @since Release 9.0.0 */ -final class Finder +final class Finder implements JsonSerializable { private array $paths; private array $excludes; @@ -44,6 +45,15 @@ public function __construct(Resolver $configResolver) $this->extensions = $configResolver->getOption(OptionDefinition::EXTENSIONS); } + public function jsonSerialize(): array + { + return [ + 'paths' => $this->paths, + 'excludes' => $this->excludes, + 'extensions' => $this->extensions, + ]; + } + public function getFiles(): SymfonyFinder { $finder = new SymfonyFinder(); From 87ceeef947482500e7218d596f3dd4ccfc650c30 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 09:52:30 +0000 Subject: [PATCH 22/28] fix issue #183 --- .../unreleased/Fixed-20230222-095158.yaml | 4 + examples/empty_dir/.gitkeep | 0 examples/no-source-to-lint.php | 43 +++++++++ src/Command/LintCommand.php | 3 +- src/Linter.php | 96 +++++++++++-------- tests/Finder/FinderTest.php | 25 +++++ 6 files changed, 127 insertions(+), 44 deletions(-) create mode 100644 .changes/unreleased/Fixed-20230222-095158.yaml create mode 100644 examples/empty_dir/.gitkeep create mode 100644 examples/no-source-to-lint.php diff --git a/.changes/unreleased/Fixed-20230222-095158.yaml b/.changes/unreleased/Fixed-20230222-095158.yaml new file mode 100644 index 00000000..8739a4a8 --- /dev/null +++ b/.changes/unreleased/Fixed-20230222-095158.yaml @@ -0,0 +1,4 @@ +kind: Fixed +body: '[#183](https://github.com/overtrue/phplint/issues/183) : Error is unintuitive + when there are no files to lint' +time: 2023-02-22T09:51:58.768580209Z diff --git a/examples/empty_dir/.gitkeep b/examples/empty_dir/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/examples/no-source-to-lint.php b/examples/no-source-to-lint.php new file mode 100644 index 00000000..de929439 --- /dev/null +++ b/examples/no-source-to-lint.php @@ -0,0 +1,43 @@ + [__DIR__ . '/empty_dir', __DIR__ . '/missing_dir'], + '--no-configuration' => true, +]; +$command = new LintCommand($dispatcher); +$input = new ArrayInput($arguments, $command->getDefinition()); +$configResolver = new ConsoleOptionsResolver($input); + +$finder = (new Finder($configResolver)); //->getFiles(); +$linter = new Linter($configResolver, $dispatcher); +$results = $linter->lintFiles($finder->getFiles()); + +var_dump("Files checked :", count($results)); + +if (count($results) === 0) { + throw new LogicException( + sprintf("Could not find any files to lint with this Finder %s", json_encode($finder)) + ); +} diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php index aeca7793..ffe1a4fd 100644 --- a/src/Command/LintCommand.php +++ b/src/Command/LintCommand.php @@ -89,7 +89,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $finder = (new Finder($configResolver))->getFiles(); - $fileCount = count($finder); /** @var Application $app */ $app = $this->getApplication(); $linter = new Linter($configResolver, $this->dispatcher, $app->getLongVersion()); @@ -101,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::SUCCESS; } - if ($fileCount === 0 || count($data)) { + if (count($this->results) === 0 || count($data)) { return self::FAILURE; } diff --git a/src/Linter.php b/src/Linter.php index e0a24dce..5dfe03a3 100644 --- a/src/Linter.php +++ b/src/Linter.php @@ -13,6 +13,7 @@ namespace Overtrue\PHPLint; +use LogicException; use Overtrue\PHPLint\Configuration\OptionDefinition; use Overtrue\PHPLint\Configuration\Resolver; use Overtrue\PHPLint\Event\AfterCheckingEvent; @@ -80,61 +81,72 @@ public function lintFiles(Finder $finder, ?float $startTime = null): LinterOutpu $startTime = microtime(true); } + try { + $fileCount = count($finder); + } catch (LogicException) { + $fileCount = 0; + } + $this->dispatcher->dispatch( new BeforeCheckingEvent( $this, - ['fileCount' => count($finder), 'appVersion' => $this->appLongVersion, 'options' => $this->options] + ['fileCount' => $fileCount, 'appVersion' => $this->appLongVersion, 'options' => $this->options] ) ); - $pid = 0; - $processRunning = []; - $iterator = $finder->getIterator(); - - while ($iterator->valid() || !empty($processRunning)) { - for ($i = count($processRunning); $iterator->valid() && $i < $this->processLimit; ++$i) { - $fileInfo = $iterator->current(); - $this->dispatcher->dispatch(new BeforeLintFileEvent($this, ['file' => $fileInfo])); - $filename = $fileInfo->getRealPath(); - - if ($this->cache->isHit($filename)) { - $this->results['hits'][] = $filename; - } else { - $lintProcess = $this->createLintProcess($filename); - $lintProcess->start(); - - ++$pid; - $processRunning[$pid] = [ - 'process' => $lintProcess, - 'file' => $fileInfo, - ]; - $this->results['misses'][] = $filename; + if ($fileCount > 0) { + $pid = 0; + $processRunning = []; + $iterator = $finder->getIterator(); + + while ($iterator->valid() || !empty($processRunning)) { + for ($i = count($processRunning); $iterator->valid() && $i < $this->processLimit; ++$i) { + $fileInfo = $iterator->current(); + $this->dispatcher->dispatch(new BeforeLintFileEvent($this, ['file' => $fileInfo])); + $filename = $fileInfo->getRealPath(); + + if ($this->cache->isHit($filename)) { + $this->results['hits'][] = $filename; + } else { + $lintProcess = $this->createLintProcess($filename); + $lintProcess->start(); + + ++$pid; + $processRunning[$pid] = [ + 'process' => $lintProcess, + 'file' => $fileInfo, + ]; + $this->results['misses'][] = $filename; + } + + $iterator->next(); } - $iterator->next(); - } - - foreach ($processRunning as $pid => $item) { - /** @var LintProcess $lintProcess */ - $lintProcess = $item['process']; - if ($lintProcess->isRunning()) { - continue; + foreach ($processRunning as $pid => $item) { + /** @var LintProcess $lintProcess */ + $lintProcess = $item['process']; + if ($lintProcess->isRunning()) { + continue; + } + /** @var SplFileInfo $fileInfo */ + $fileInfo = $item['file']; + $status = $this->processFile($fileInfo, $lintProcess); + + unset($processRunning[$pid]); + $this->dispatcher->dispatch(new AfterLintFileEvent($this, ['file' => $fileInfo, 'status' => $status])); } - /** @var SplFileInfo $fileInfo */ - $fileInfo = $item['file']; - $status = $this->processFile($fileInfo, $lintProcess); - - unset($processRunning[$pid]); - $this->dispatcher->dispatch(new AfterLintFileEvent($this, ['file' => $fileInfo, 'status' => $status])); } - } - $results = new LinterOutput($this->results, $finder); - $results->setContext($this->configResolver, $startTime); + $results = $this->results; + } else { + $results = []; + } + $finalResults = new LinterOutput($results, $finder); + $finalResults->setContext($this->configResolver, $startTime); - $this->dispatcher->dispatch(new AfterCheckingEvent($this, ['results' => $results])); + $this->dispatcher->dispatch(new AfterCheckingEvent($this, ['results' => $finalResults])); - return $results; + return $finalResults; } private function processFile(SplFileInfo $fileInfo, LintProcess $lintProcess): string diff --git a/tests/Finder/FinderTest.php b/tests/Finder/FinderTest.php index 83d80de5..6fa8b702 100644 --- a/tests/Finder/FinderTest.php +++ b/tests/Finder/FinderTest.php @@ -14,6 +14,7 @@ namespace Overtrue\PHPLint\Tests\Finder; use Iterator; +use LogicException; use Overtrue\PHPLint\Command\LintCommand; use Overtrue\PHPLint\Configuration\ConsoleOptionsResolver; use Overtrue\PHPLint\Configuration\OptionDefinition; @@ -61,6 +62,30 @@ public function testAllPhpFilesFoundShouldExists(): void } } + /** + * @covers \Overtrue\PHPLint\Finder::getFiles + */ + public function testAllPathShouldExistsAndReadable(): void + { + $this->expectException(LogicException::class); + + $dispatcher = new EventDispatcher([]); + + $basePath = dirname(__DIR__) . '/fixtures/missing_dir'; + + $arguments = [ + OptionDefinition::PATH => [$basePath], + '--no-configuration' => true, + ]; + $definition = (new LintCommand($dispatcher))->getDefinition(); + $input = new ArrayInput($arguments, $definition); + + $configResolver = new ConsoleOptionsResolver($input); + + $finder = new Finder($configResolver); + count($finder->getFiles()); + } + /** * @covers \Overtrue\PHPLint\Finder::getFiles */ From 6465bb7826ccc69a5e322a4057d229bcac1bf1be Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 13:42:00 +0000 Subject: [PATCH 23/28] multiple path syntax (may be also used as single path syntax) --- .phplint.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.phplint.yml b/.phplint.yml index 65bef3b3..ecb20486 100644 --- a/.phplint.yml +++ b/.phplint.yml @@ -1,4 +1,6 @@ -path: ./src +path: + - src/ + - tests/ jobs: 10 extensions: - php From 9002c8f57331010999c80313bfe66f9b1b4553d6 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Wed, 22 Feb 2023 13:52:34 +0000 Subject: [PATCH 24/28] fix issue #185 --- .changes/unreleased/Fixed-20230222-135209.yaml | 4 ++++ src/Command/LintCommand.php | 10 ++++------ tests/Configuration/ConsoleConfigTest.php | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 .changes/unreleased/Fixed-20230222-135209.yaml diff --git a/.changes/unreleased/Fixed-20230222-135209.yaml b/.changes/unreleased/Fixed-20230222-135209.yaml new file mode 100644 index 00000000..a56200a5 --- /dev/null +++ b/.changes/unreleased/Fixed-20230222-135209.yaml @@ -0,0 +1,4 @@ +kind: Fixed +body: '[#185](https://github.com/overtrue/phplint/issues/185) : Analyse multiple path + at same time did not work with console command' +time: 2023-02-22T13:52:09.277748038Z diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php index ffe1a4fd..1bb62255 100644 --- a/src/Command/LintCommand.php +++ b/src/Command/LintCommand.php @@ -28,6 +28,7 @@ use Symfony\Component\Finder\Finder as SymfonyFinder; use Throwable; +use function array_unshift; use function count; use function microtime; @@ -64,13 +65,10 @@ protected function initialize(InputInterface $input, OutputInterface $output): v { // initializes correctly command and path arguments when lint is set as default command $cmd = $input->getArgument('command'); - - if ($cmd === $this->getName()) { - $paths = $input->getArgument('path'); - } else { - $paths = [$cmd]; + $paths = $input->getArgument('path'); + if ($cmd !== $this->getName()) { + array_unshift($paths, $cmd); } - $input->setArgument('path', $paths); $input->setArgument('command', $this->getName()); } diff --git a/tests/Configuration/ConsoleConfigTest.php b/tests/Configuration/ConsoleConfigTest.php index 7174fa8d..a1b8a137 100644 --- a/tests/Configuration/ConsoleConfigTest.php +++ b/tests/Configuration/ConsoleConfigTest.php @@ -63,6 +63,7 @@ public static function commandInputProvider(): array return [ 'only default values' => [[], __CLASS__ . '::expectedOnlyDefaults'], 'only path modified' => [['path' => dirname(__DIR__)], __CLASS__ . '::expectedPathModified'], + 'multiple path modified' => [['path' => [dirname(__DIR__) . '/Cache', __DIR__]], __CLASS__ . '::expectedPathModified'], 'without external configuration' => [['--no-configuration' => true], __CLASS__ . '::expectedExternalConfigNotFetched'], 'with external empty configuration' => [['--configuration' => 'tests/Configuration/empty.yaml'], __CLASS__ . '::expectedExternalEmptyConfig'], 'output to JSON format on Stdout' => [['--log-json' => null], __CLASS__ . '::expectedJsonOutputFormat'], @@ -80,7 +81,7 @@ protected static function expectedOnlyDefaults(Resolver $resolver): array protected static function expectedPathModified(Resolver $resolver, array $arguments): array { $expected = self::getExpectedValues($resolver); - $expected['path'] = [$arguments['path']]; + $expected['path'] = (array) $arguments['path']; return $expected; } From 1f02db52eb3a6d725f143ffad40d4eb799af39e0 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Thu, 23 Feb 2023 06:58:41 +0000 Subject: [PATCH 25/28] release workflow is now triggered only when pushing new tag --- .github/workflows/release.yml | 54 ++++++----------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e777e46d..83adea1c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,35 +3,8 @@ name: Release on: push: - branches: tags: - "[0-9]+.[0-9]+.[0-9]+" - workflow_dispatch: - # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/ - inputs: - box-output: - description: "Path to the PHP Archive made by the BOX" - required: true - type: string - release-tag: - description: "Tag that identify version to be released" - required: true - type: string - release-draft: - description: "Indicator of whether or not this release is a draft" - required: false - default: false - type: boolean - changie-changesDir: - description: "Directory for change files, header file and unreleased files. Relative to project root" - required: false - default: ".changes" - type: string - changie-version: - description: "Version for Changie" - required: false - default: v1.11.1 - type: string permissions: contents: write @@ -44,7 +17,7 @@ jobs: fail-fast: false matrix: os: - - ubuntu-20.04 + - ubuntu-22.04 php: - 8.1 @@ -65,27 +38,17 @@ jobs: with: composer-options: "--prefer-dist" - - # Build the current change fragments - name: Build Release Notes 1/2 - uses: miniscruff/changie-action@v1 - with: - version: ${{ github.event.inputs.changie-version }} - args: batch ${{ github.event.inputs.release-tag }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Build the current release changelog - name: Build Release Notes 2/2 + name: Build Release Notes uses: miniscruff/changie-action@v1 with: - version: ${{ github.event.inputs.changie-version }} + version: latest args: merge env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Build the current release with artifacts (php archive) - name: Build Release Artifacts (without bootstrap file) - if: endsWith(github.event.inputs.box-output, '.phar') + name: Build Release Artifacts run: | cd ${{ github.workspace }} curl -Ls https://github.com/llaville/box-manifest/releases/latest/download/box-manifest.phar -o /usr/local/bin/box-manifest @@ -94,13 +57,14 @@ jobs: - # Create a new Release (from a tag) name: Create Release from current tag + if: github.ref_type == 'tag' uses: softprops/action-gh-release@v1 with: # https://github.com/softprops/action-gh-release#-customizing prerelease: false - draft: ${{ github.event.inputs.release-draft }} - body_path: ${{ github.workspace }}/${{ github.event.inputs.changie-changesDir }}/${{ github.event.inputs.release-tag }}.md + draft: true + body_path: ${{ github.workspace }}/.changes/${{ github.ref_name }}.md # https://github.com/softprops/action-gh-release#%EF%B8%8F-uploading-release-assets files: - ${{ github.workspace }}/${{ github.event.inputs.box-output }} + ${{ github.workspace }}/bin/phplint.phar fail_on_unmatched_files: true - tag_name: ${{ github.event.inputs.release-tag }} + tag_name: ${{ github.ref_name }} From 1cbfb3966738410273ae73d7104cf576166a0c75 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Thu, 23 Feb 2023 15:35:44 +0000 Subject: [PATCH 26/28] release workflow is again more easy (CHANGELOG.md should be built before this workflow is triggered) --- .github/workflows/release.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 83adea1c..a3a27b30 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,15 +38,6 @@ jobs: with: composer-options: "--prefer-dist" - - # Build the current release changelog - name: Build Release Notes - uses: miniscruff/changie-action@v1 - with: - version: latest - args: merge - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Build the current release with artifacts (php archive) name: Build Release Artifacts run: | From 4cb2bd254774a8e74c866ba79deae9dc264d3633 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Thu, 23 Feb 2023 15:39:24 +0000 Subject: [PATCH 27/28] fix issue #187 --- .../unreleased/Fixed-20230223-153848.yaml | 4 ++ src/Configuration/AbstractOptionsResolver.php | 19 +++++- src/Configuration/OptionsFactory.php | 62 ++++++++++++++++--- tests/Configuration/ConsoleConfigTest.php | 20 ++++-- tests/Configuration/YamlConfigTest.php | 10 +-- 5 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 .changes/unreleased/Fixed-20230223-153848.yaml diff --git a/.changes/unreleased/Fixed-20230223-153848.yaml b/.changes/unreleased/Fixed-20230223-153848.yaml new file mode 100644 index 00000000..2f63604f --- /dev/null +++ b/.changes/unreleased/Fixed-20230223-153848.yaml @@ -0,0 +1,4 @@ +kind: Fixed +body: '[#187](https://github.com/overtrue/phplint/issues/187) : Improve log options + implementation' +time: 2023-02-23T15:38:48.338553903Z diff --git a/src/Configuration/AbstractOptionsResolver.php b/src/Configuration/AbstractOptionsResolver.php index 59f0021d..755caa35 100644 --- a/src/Configuration/AbstractOptionsResolver.php +++ b/src/Configuration/AbstractOptionsResolver.php @@ -45,8 +45,8 @@ public function __construct(InputInterface $input, array $configuration = []) OptionDefinition::NO_CACHE => false, OptionDefinition::PROGRESS => OptionDefinition::DEFAULT_PROGRESS_WIDGET, OptionDefinition::NO_PROGRESS => false, - OptionDefinition::LOG_JSON => null, - OptionDefinition::LOG_JUNIT => null, + OptionDefinition::LOG_JSON => false, + OptionDefinition::LOG_JUNIT => false, OptionDefinition::WARNING => false, OptionDefinition::OPTION_MEMORY_LIMIT => ini_get('memory_limit'), OptionDefinition::IGNORE_EXIT_CODE => false, @@ -76,6 +76,21 @@ public function __construct(InputInterface $input, array $configuration = []) unset($options['warning']); } + // log options that accept : + // - NULL or empty string are values considered to enable output format for standard output + // - a string to identify stream + $names = [ + OptionDefinition::LOG_JSON, + OptionDefinition::LOG_JUNIT, + ]; + foreach ($names as $name) { + if ('' === $options[$name]) { + $options[$name] = true; + } elseif (null === $options[$name] && (true === $input->hasParameterOption(['--' . $name], true))) { + $options[$name] = true; + } + } + // options that cannot be overridden by YAML config file values $names = [ OptionDefinition::CONFIGURATION, diff --git a/src/Configuration/OptionsFactory.php b/src/Configuration/OptionsFactory.php index 43b9dcdf..e406c90e 100644 --- a/src/Configuration/OptionsFactory.php +++ b/src/Configuration/OptionsFactory.php @@ -13,10 +13,16 @@ namespace Overtrue\PHPLint\Configuration; +use Closure; use Symfony\Component\OptionsResolver\Options as SymfonyOptions; use Symfony\Component\OptionsResolver\OptionsResolver; use function array_keys; +use function filter_var; +use function in_array; +use function is_bool; + +use const FILTER_VALIDATE_BOOLEAN; /** * @author Laurent Laville @@ -52,8 +58,8 @@ protected function configureOptions(OptionsResolver $resolver): void OptionDefinition::NO_CACHE => 'bool', OptionDefinition::PROGRESS => ['null', 'string'], OptionDefinition::NO_PROGRESS => 'bool', - OptionDefinition::LOG_JSON => ['bool', 'null', 'string'], - OptionDefinition::LOG_JUNIT => ['bool', 'null', 'string'], + OptionDefinition::LOG_JSON => ['bool', 'string'], + OptionDefinition::LOG_JUNIT => ['bool', 'string'], OptionDefinition::WARNING => 'bool', OptionDefinition::OPTION_MEMORY_LIMIT => ['int', 'string'], OptionDefinition::IGNORE_EXIT_CODE => 'bool', @@ -81,13 +87,49 @@ protected function configureOptions(OptionsResolver $resolver): void return (int) $value; }); - $outputFormat = function (SymfonyOptions $options, $value) { - if (true === $value) { - $value = OptionDefinition::DEFAULT_STANDARD_OUTPUT; - } - return $value; - }; - $resolver->setNormalizer(OptionDefinition::LOG_JSON, $outputFormat); - $resolver->setNormalizer(OptionDefinition::LOG_JUNIT, $outputFormat); + $names = [ + OptionDefinition::LOG_JSON, + OptionDefinition::LOG_JUNIT, + ]; + foreach ($names as $name) { + $resolver->setNormalizer($name, Closure::fromCallable([$this, 'logNormalizer'])); + } + } + + /** + * Reused by unit tests suite ConsoleConfigTest + */ + public static function logNormalizer(SymfonyOptions $options, $value) + { + $bool = static::toBool($value); + if (is_bool($bool)) { + $value = $bool ? OptionDefinition::DEFAULT_STANDARD_OUTPUT : false; + } + return $value; + } + + /** + * Best strategy to convert string to boolean + * + * + * @link https://stackoverflow.com/questions/7336861/how-to-convert-string-to-boolean-php#answer-15075609 + * @link https://www.php.net/manual/en/function.filter-var + */ + public static function toBool(mixed $value): bool|int + { + $booleanValueDomain = [ + false, 'false', 0, '0', 'off', 'no', + true, 'true', 1, '1', 'on', 'yes', + ]; + + if (in_array($value, ['', null], true)) { + // CAUTION: null or empty string must be considered as logging to standard output (like true boolean value) + $out = true; + } elseif (in_array($value, $booleanValueDomain, true)) { + $out = filter_var($value, FILTER_VALIDATE_BOOLEAN); + } else { + $out = -1; + } + return $out; } } diff --git a/tests/Configuration/ConsoleConfigTest.php b/tests/Configuration/ConsoleConfigTest.php index a1b8a137..a94865b7 100644 --- a/tests/Configuration/ConsoleConfigTest.php +++ b/tests/Configuration/ConsoleConfigTest.php @@ -16,13 +16,15 @@ use Overtrue\PHPLint\Command\LintCommand; use Overtrue\PHPLint\Configuration\ConsoleOptionsResolver; use Overtrue\PHPLint\Configuration\OptionDefinition; +use Overtrue\PHPLint\Configuration\OptionsFactory; use Overtrue\PHPLint\Configuration\Resolver; use Overtrue\PHPLint\Event\EventDispatcher; use Overtrue\PHPLint\Tests\TestCase; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\OptionsResolver\OptionsResolver; + use function dirname; -use function is_string; use function realpath; final class ConsoleConfigTest extends TestCase @@ -66,9 +68,17 @@ public static function commandInputProvider(): array 'multiple path modified' => [['path' => [dirname(__DIR__) . '/Cache', __DIR__]], __CLASS__ . '::expectedPathModified'], 'without external configuration' => [['--no-configuration' => true], __CLASS__ . '::expectedExternalConfigNotFetched'], 'with external empty configuration' => [['--configuration' => 'tests/Configuration/empty.yaml'], __CLASS__ . '::expectedExternalEmptyConfig'], - 'output to JSON format on Stdout' => [['--log-json' => null], __CLASS__ . '::expectedJsonOutputFormat'], + 'output to JSON format on Stdout 1/3' => [['--log-json' => null], __CLASS__ . '::expectedJsonOutputFormat'], + 'output to JSON format on Stdout 2/3' => [['--log-json' => ''], __CLASS__ . '::expectedJsonOutputFormat'], + 'output to JSON format on Stdout 3/3' => [['--log-json' => true], __CLASS__ . '::expectedJsonOutputFormat'], + 'disable output to JSON format 1/2' => [['--log-json' => false], __CLASS__ . '::expectedJsonOutputFormat'], + 'disable output to JSON format 2/2' => [['--log-json' => 'off'], __CLASS__ . '::expectedJsonOutputFormat'], 'output to JSON format on File' => [['--log-json' => '/tmp/phplint.json'], __CLASS__ . '::expectedJsonOutputFormat'], - 'output to XML format on Stdout' => [['--log-junit' => true], __CLASS__ . '::expectedXmlOutputFormat'], + 'output to XML format on Stdout 1/3' => [['--log-junit' => null], __CLASS__ . '::expectedXmlOutputFormat'], + 'output to XML format on Stdout 2/3' => [['--log-junit' => ''], __CLASS__ . '::expectedXmlOutputFormat'], + 'output to XML format on Stdout 3/3' => [['--log-junit' => true], __CLASS__ . '::expectedXmlOutputFormat'], + 'disable output to XML format 1/2' => [['--log-junit' => false], __CLASS__ . '::expectedXmlOutputFormat'], + 'disable output to XML format 2/2' => [['--log-junit' => 'FALSE'], __CLASS__ . '::expectedXmlOutputFormat'], 'output to XML format on File' => [['--log-junit' => '/tmp/phplint.xml'], __CLASS__ . '::expectedXmlOutputFormat'], ]; } @@ -99,7 +109,7 @@ protected static function expectedJsonOutputFormat(Resolver $resolver, array $ar { $expected = self::getExpectedValues($resolver); $logJson = $arguments['--log-json']; - $expected['log-json'] = (is_string($logJson)) ? $logJson : (empty($logJson) ? null : 'php://stdout'); + $expected['log-json'] = OptionsFactory::logNormalizer(new OptionsResolver(), $logJson); return $expected; } @@ -107,7 +117,7 @@ protected static function expectedXmlOutputFormat(Resolver $resolver, array $arg { $expected = self::getExpectedValues($resolver); $logJunit = $arguments['--log-junit']; - $expected['log-junit'] = (is_string($logJunit)) ? $logJunit : (empty($logJunit) ? null : 'php://stdout'); + $expected['log-junit'] = OptionsFactory::logNormalizer(new OptionsResolver(), $logJunit); return $expected; } diff --git a/tests/Configuration/YamlConfigTest.php b/tests/Configuration/YamlConfigTest.php index a59ae0b7..977e6e72 100644 --- a/tests/Configuration/YamlConfigTest.php +++ b/tests/Configuration/YamlConfigTest.php @@ -15,6 +15,8 @@ use Overtrue\PHPLint\Command\LintCommand; use Overtrue\PHPLint\Configuration\FileOptionsResolver; +use Overtrue\PHPLint\Configuration\OptionDefinition; +use Overtrue\PHPLint\Configuration\OptionsFactory; use Overtrue\PHPLint\Configuration\Resolver; use Overtrue\PHPLint\Event\EventDispatcher; use Overtrue\PHPLint\Tests\TestCase; @@ -88,17 +90,17 @@ protected static function expectedJobsModified(Resolver $resolver): array return $expected; } - protected static function expectedJsonOutputFormat(Resolver $resolver): array + protected static function expectedJsonOutputFormat(Resolver $resolver, array $arguments): array { $expected = self::getExpectedValues($resolver); - $expected['log-json'] = 'php://stdout'; // see 'log-json.yaml' contents + $expected['log-json'] = OptionDefinition::DEFAULT_STANDARD_OUTPUT; // see 'log-json.yaml' contents return $expected; } - protected static function expectedXmlOutputFormat(Resolver $resolver): array + protected static function expectedXmlOutputFormat(Resolver $resolver, array $arguments): array { $expected = self::getExpectedValues($resolver); - $expected['log-junit'] = '/tmp/phplint-results.xml'; // see 'log-junit.yaml' contents + $expected['log-junit'] = '/tmp/phplint-results.xml'; // see 'log-junit.yaml' contents return $expected; } From da8aa332372fbbf9aed174ed45ad190aed848b9a Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Thu, 23 Feb 2023 15:46:09 +0000 Subject: [PATCH 28/28] prepare bugfix release 9.0.4 --- .changes/9.0.4.md | 21 +++++++++++++++++++ .../unreleased/Added-20230219-083856.yaml | 3 --- .../unreleased/Changed-20230222-085355.yaml | 3 --- .../unreleased/Changed-20230222-085614.yaml | 3 --- .../unreleased/Changed-20230222-093931.yaml | 3 --- .../unreleased/Fixed-20230219-150315.yaml | 4 ---- .../unreleased/Fixed-20230222-095158.yaml | 4 ---- .../unreleased/Fixed-20230222-135209.yaml | 4 ---- .../unreleased/Fixed-20230223-153848.yaml | 4 ---- CHANGELOG.md | 21 +++++++++++++++++++ src/Console/Application.php | 2 +- 11 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 .changes/9.0.4.md delete mode 100644 .changes/unreleased/Added-20230219-083856.yaml delete mode 100644 .changes/unreleased/Changed-20230222-085355.yaml delete mode 100644 .changes/unreleased/Changed-20230222-085614.yaml delete mode 100644 .changes/unreleased/Changed-20230222-093931.yaml delete mode 100644 .changes/unreleased/Fixed-20230219-150315.yaml delete mode 100644 .changes/unreleased/Fixed-20230222-095158.yaml delete mode 100644 .changes/unreleased/Fixed-20230222-135209.yaml delete mode 100644 .changes/unreleased/Fixed-20230223-153848.yaml diff --git a/.changes/9.0.4.md b/.changes/9.0.4.md new file mode 100644 index 00000000..da03e3e9 --- /dev/null +++ b/.changes/9.0.4.md @@ -0,0 +1,21 @@ + +## 9.0.4 - 2023-02-23 + +### Added + +- PHPUnit 10 support + +### Changed + +- ConsoleOutput is no more final to be able to customize it +- LinterOutput implement Countable interface +- Finder implement JsonSerializable interface + +### Fixed + +- [#182](https://github.com/overtrue/phplint/issues/182) : Docker usage may raise a permission denied +- [#183](https://github.com/overtrue/phplint/issues/183) : Error is unintuitive when there are no files to lint +- [#185](https://github.com/overtrue/phplint/issues/185) : Analyse multiple path at same time did not work with console command +- [#187](https://github.com/overtrue/phplint/issues/187) : Improve log options implementation + +**Full Changelog**: [9.0.3...9.0.4](https://github.com/overtrue/phplint/compare/9.0.3...9.0.4) diff --git a/.changes/unreleased/Added-20230219-083856.yaml b/.changes/unreleased/Added-20230219-083856.yaml deleted file mode 100644 index 64e4a9ab..00000000 --- a/.changes/unreleased/Added-20230219-083856.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: Added -body: PHPUnit 10 support -time: 2023-02-19T08:38:56.407648037Z diff --git a/.changes/unreleased/Changed-20230222-085355.yaml b/.changes/unreleased/Changed-20230222-085355.yaml deleted file mode 100644 index e1b7c1a1..00000000 --- a/.changes/unreleased/Changed-20230222-085355.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: Changed -body: ConsoleOutput is no more final to be able to customize it -time: 2023-02-22T08:53:55.559059951Z diff --git a/.changes/unreleased/Changed-20230222-085614.yaml b/.changes/unreleased/Changed-20230222-085614.yaml deleted file mode 100644 index c7fd138a..00000000 --- a/.changes/unreleased/Changed-20230222-085614.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: Changed -body: LinterOutput implement Countable interface -time: 2023-02-22T08:56:14.33882874Z diff --git a/.changes/unreleased/Changed-20230222-093931.yaml b/.changes/unreleased/Changed-20230222-093931.yaml deleted file mode 100644 index af9a0c01..00000000 --- a/.changes/unreleased/Changed-20230222-093931.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: Changed -body: Finder implement JsonSerializable interface -time: 2023-02-22T09:39:31.716821987Z diff --git a/.changes/unreleased/Fixed-20230219-150315.yaml b/.changes/unreleased/Fixed-20230219-150315.yaml deleted file mode 100644 index 3efda0a2..00000000 --- a/.changes/unreleased/Fixed-20230219-150315.yaml +++ /dev/null @@ -1,4 +0,0 @@ -kind: Fixed -body: '[#182](https://github.com/overtrue/phplint/issues/182) : Docker usage may raise - a permission denied' -time: 2023-02-19T15:03:15.555779829Z diff --git a/.changes/unreleased/Fixed-20230222-095158.yaml b/.changes/unreleased/Fixed-20230222-095158.yaml deleted file mode 100644 index 8739a4a8..00000000 --- a/.changes/unreleased/Fixed-20230222-095158.yaml +++ /dev/null @@ -1,4 +0,0 @@ -kind: Fixed -body: '[#183](https://github.com/overtrue/phplint/issues/183) : Error is unintuitive - when there are no files to lint' -time: 2023-02-22T09:51:58.768580209Z diff --git a/.changes/unreleased/Fixed-20230222-135209.yaml b/.changes/unreleased/Fixed-20230222-135209.yaml deleted file mode 100644 index a56200a5..00000000 --- a/.changes/unreleased/Fixed-20230222-135209.yaml +++ /dev/null @@ -1,4 +0,0 @@ -kind: Fixed -body: '[#185](https://github.com/overtrue/phplint/issues/185) : Analyse multiple path - at same time did not work with console command' -time: 2023-02-22T13:52:09.277748038Z diff --git a/.changes/unreleased/Fixed-20230223-153848.yaml b/.changes/unreleased/Fixed-20230223-153848.yaml deleted file mode 100644 index 2f63604f..00000000 --- a/.changes/unreleased/Fixed-20230223-153848.yaml +++ /dev/null @@ -1,4 +0,0 @@ -kind: Fixed -body: '[#187](https://github.com/overtrue/phplint/issues/187) : Improve log options - implementation' -time: 2023-02-23T15:38:48.338553903Z diff --git a/CHANGELOG.md b/CHANGELOG.md index 2afb64da..4678a4d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). +## 9.0.4 - 2023-02-23 + +### Added + +- PHPUnit 10 support + +### Changed + +- ConsoleOutput is no more final to be able to customize it +- LinterOutput implement Countable interface +- Finder implement JsonSerializable interface + +### Fixed + +- [#182](https://github.com/overtrue/phplint/issues/182) : Docker usage may raise a permission denied +- [#183](https://github.com/overtrue/phplint/issues/183) : Error is unintuitive when there are no files to lint +- [#185](https://github.com/overtrue/phplint/issues/185) : Analyse multiple path at same time did not work with console command +- [#187](https://github.com/overtrue/phplint/issues/187) : Improve log options implementation + +**Full Changelog**: [9.0.3...9.0.4](https://github.com/overtrue/phplint/compare/9.0.3...9.0.4) + ## 9.0.3 - 2023-02-14 ### Fixed diff --git a/src/Console/Application.php b/src/Console/Application.php index d96b4ff1..0ffb521d 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -33,7 +33,7 @@ final class Application extends BaseApplication { public const NAME = 'phplint'; - public const VERSION = '9.0.3'; + public const VERSION = '9.0.4'; public function __construct() {