-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to phpcs and upgrade codebase (#2596)
To be consistent with other MongoDB PHP projects, we use phpcs to analyze and fix the code style. Summary of changes: - added "declare(strict_types=1);" to all file headers - added "use function" for all functions used in each file (performance gain for functions with specific opcode compilation) - use of short closures - remove `@var` annotations in tests, replaced by `assertInstanceOf` or `assert` - Use early exit when appropriate, but disable the rule - Remove `@param` & `@return` phpdoc when duplicate of native types
- Loading branch information
Showing
90 changed files
with
2,101 additions
and
1,901 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: "Coding Standards" | ||
|
||
on: | ||
push: | ||
branches: | ||
tags: | ||
pull_request: | ||
|
||
env: | ||
PHP_VERSION: "8.2" | ||
DRIVER_VERSION: "stable" | ||
|
||
jobs: | ||
phpcs: | ||
name: "phpcs" | ||
runs-on: "ubuntu-22.04" | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v3" | ||
|
||
- name: Setup cache environment | ||
id: extcache | ||
uses: shivammathur/cache-extensions@v1 | ||
with: | ||
php-version: ${{ env.PHP_VERSION }} | ||
extensions: "mongodb-${{ env.DRIVER_VERSION }}" | ||
key: "extcache-v1" | ||
|
||
- name: Cache extensions | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.extcache.outputs.dir }} | ||
key: ${{ steps.extcache.outputs.key }} | ||
restore-keys: ${{ steps.extcache.outputs.key }} | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
extensions: "mongodb-${{ env.DRIVER_VERSION }}" | ||
php-version: "${{ env.PHP_VERSION }}" | ||
tools: "cs2pr" | ||
|
||
- name: "Show driver information" | ||
run: "php --ri mongodb" | ||
|
||
- name: "Install dependencies with Composer" | ||
uses: "ramsey/[email protected]" | ||
with: | ||
composer-options: "--no-suggest" | ||
|
||
# The -q option is required until phpcs v4 is released | ||
- name: "Run PHP_CodeSniffer" | ||
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0"?> | ||
<ruleset> | ||
<arg name="basepath" value="." /> | ||
<arg name="extensions" value="php" /> | ||
<arg name="parallel" value="80" /> | ||
<arg name="cache" value=".phpcs-cache" /> | ||
<arg name="colors" /> | ||
|
||
<!-- Ignore warnings (n), show progress of the run (p), and show sniff names (s) --> | ||
<arg value="nps"/> | ||
|
||
<file>src</file> | ||
<file>tests</file> | ||
|
||
<!-- Target minimum supported PHP version --> | ||
<config name="php_version" value="80100"/> | ||
|
||
<!-- ****************************************** --> | ||
<!-- Import rules from doctrine/coding-standard --> | ||
<!-- ****************************************** --> | ||
<rule ref="Doctrine"> | ||
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/> | ||
<exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing"/> | ||
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/> | ||
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/> | ||
<exclude name="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/> | ||
<exclude name="SlevomatCodingStandard.Functions.StaticClosure"/> | ||
<exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat.DisallowedShortNullable"/> | ||
|
||
<!-- Model properties use snake_case --> | ||
<exclude name="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/> | ||
|
||
<!-- Type changes needs to be synchronized with laravel/framework --> | ||
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/> | ||
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/> | ||
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.