diff --git a/.editorconfig b/.editorconfig index b6249fbb09..9a2273c794 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,10 @@ charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true +[*.xml] +indent_size = 2 +indent_style = space + [*.yaml] indent_size = 2 indent_style = space diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index c00267ff51..2ded2d3cf3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -74,6 +74,19 @@ about what you're working on, you can contact us via the ``` to automatically fix coding standard issues. +- Run + + ```shell + make static-code-analysis + ``` + + to run a static code analysis or, if applicable, run + + ```shell + make static-code-analysis-baseline + ``` + + to regenerate the baseline. - Review the change once more just before submitting it. ## What happens after submitting contribution? @@ -133,7 +146,20 @@ Having said that, here are the organizational rules: ```shell make coding-standards ``` +6. Run + + ```shell + make static-code-analysis + ``` + + to run a static code analysis or, if applicable, run + + ```shell + make static-code-analysis-baseline + ``` + + to regenerate the baseline. -6. Use reasonable commit messages. +7. Use reasonable commit messages. Thank you for contributing to https://www.php.net! diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index e4d6abcd00..e635a75913 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -77,7 +77,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "none" - extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter" + extensions: "none, curl, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" - name: "Set up problem matchers for PHP" @@ -102,6 +102,49 @@ jobs: - name: "Run friendsofphp/php-cs-fixer" run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --show-progress=dots --verbose" + static-code-analysis: + name: "Static Code Analysis" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "8.2" + + dependencies: + - "locked" + + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "none, dom, json, mbstring, opcache, pcntl, posix, simplexml, tokenizer" + php-version: "${{ matrix.php-version }}" + + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + + - name: "Determine composer cache directory" + run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v3" + with: + path: "${{ env.COMPOSER_CACHE_DIR }}" + key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-" + + - name: "Install dependencies with composer" + run: "composer install --ansi --no-interaction --no-progress" + + - name: "Run vimeo/psalm" + run: "vendor/bin/psalm --config=psalm.xml --output-format=github --shepherd --show-info=false --stats --threads=4" + tests: name: "Tests" diff --git a/Makefile b/Makefile index 23b2f9c321..0f656059e7 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,14 @@ code-coverage: vendor ## Collects coverage from running tests with phpunit/phpun coding-standards: vendor ## Fixes code style issues with friendsofphp/php-cs-fixer vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --show-progress=dots --verbose +.PHONY: static-code-analysis +static-code-analysis: vendor ## Runs a static code analysis with vimeo/psalm + vendor/bin/psalm --config=psalm.xml --show-info=true --stats --threads=4 + +.PHONY: static-code-analysis-baseline +static-code-analysis-baseline: vendor ## Generates a baseline for static code analysis with vimeo/psalm + vendor/bin/psalm --config=psalm.xml --set-baseline=psalm-baseline.xml + .PHONY: tests tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit vendor/bin/phpunit --configuration=tests/phpunit.xml --testsuite=unit diff --git a/README.md b/README.md index 39b7c4c47b..80ed7f1091 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Integrate](https://github.com/php/web-php/actions/workflows/integrate.yaml/badge.svg)](https://github.com/php/web-php/actions/workflows/integrate.yaml) +[![Type Coverage](https://shepherd.dev/github/php/web-php/coverage.svg)](https://shepherd.dev/github/php/web-php) ## Local development diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000000..13cad7ad67 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,2 @@ + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000000..c2644f0f71 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,14 @@ + + + + + + +