Skip to content

Commit e183478

Browse files
committed
Switch to phpcs and upgrade codebase
1 parent ad79fb1 commit e183478

File tree

89 files changed

+2401
-2506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2401
-2506
lines changed

.github/workflows/build-ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ on:
77
pull_request:
88

99
jobs:
10-
php-cs-fixer:
10+
phpcs:
1111
runs-on: ubuntu-latest
12-
env:
13-
PHP_CS_FIXER_VERSION: v3.6.0
1412
strategy:
1513
matrix:
1614
php:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Coding Standards"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "v*.*"
7+
- "master"
8+
- "feature/*"
9+
push:
10+
branches:
11+
- "v*.*"
12+
- "master"
13+
- "feature/*"
14+
15+
env:
16+
PHP_VERSION: "8.2"
17+
DRIVER_VERSION: "stable"
18+
19+
jobs:
20+
phpcs:
21+
name: "phpcs"
22+
runs-on: "ubuntu-22.04"
23+
24+
steps:
25+
- name: "Checkout"
26+
uses: "actions/checkout@v3"
27+
28+
- name: Setup cache environment
29+
id: extcache
30+
uses: shivammathur/cache-extensions@v1
31+
with:
32+
php-version: ${{ env.PHP_VERSION }}
33+
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
34+
key: "extcache-v1"
35+
36+
- name: Cache extensions
37+
uses: actions/cache@v3
38+
with:
39+
path: ${{ steps.extcache.outputs.dir }}
40+
key: ${{ steps.extcache.outputs.key }}
41+
restore-keys: ${{ steps.extcache.outputs.key }}
42+
43+
- name: "Install PHP"
44+
uses: "shivammathur/setup-php@v2"
45+
with:
46+
coverage: "none"
47+
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
48+
php-version: "${{ env.PHP_VERSION }}"
49+
tools: "cs2pr"
50+
51+
- name: "Show driver information"
52+
run: "php --ri mongodb"
53+
54+
- name: "Install dependencies with Composer"
55+
uses: "ramsey/composer-install@2.2.0"
56+
with:
57+
composer-options: "--no-suggest"
58+
59+
# The -q option is required until phpcs v4 is released
60+
- name: "Run PHP_CodeSniffer"
61+
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"

.php-cs-fixer.dist.php

Lines changed: 0 additions & 187 deletions
This file was deleted.

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"require-dev": {
3434
"phpunit/phpunit": "^9.5.10",
3535
"orchestra/testbench": "^8.0",
36-
"mockery/mockery": "^1.4.4"
36+
"mockery/mockery": "^1.4.4",
37+
"doctrine/coding-standard": "12.0.x-dev"
3738
},
3839
"replace": {
3940
"jenssegers/mongodb": "self.version"
@@ -56,5 +57,10 @@
5657
]
5758
}
5859
},
59-
"minimum-stability": "dev"
60+
"minimum-stability": "dev",
61+
"config": {
62+
"allow-plugins": {
63+
"dealerdirect/phpcodesniffer-composer-installer": true
64+
}
65+
}
6066
}

phpcs.xml.dist

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="." />
4+
<arg name="extensions" value="php" />
5+
<arg name="parallel" value="80" />
6+
<arg name="cache" value=".phpcs-cache" />
7+
<arg name="colors" />
8+
9+
<!-- Ignore warnings (n), show progress of the run (p), and show sniff names (s) -->
10+
<arg value="nps"/>
11+
12+
<file>src</file>
13+
<file>tests</file>
14+
15+
<!-- Target minimum supported PHP version -->
16+
<config name="php_version" value="801000"/>
17+
18+
<!-- ****************************************** -->
19+
<!-- Import rules from doctrine/coding-standard -->
20+
<!-- ****************************************** -->
21+
<rule ref="Doctrine">
22+
</rule>
23+
24+
25+
<!-- **************************************** -->
26+
<!-- Enable rules not enforced by Doctrine CS -->
27+
<!-- **************************************** -->
28+
29+
<!-- Require arrow functions where possible -->
30+
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction"/>
31+
<!-- Forbid fully qualified names even for colliding names -->
32+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
33+
<properties>
34+
<property name="allowFallbackGlobalConstants" value="false"/>
35+
<property name="allowFallbackGlobalFunctions" value="false"/>
36+
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
37+
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
38+
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
39+
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingClasses" value="false"/>
40+
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingConstants" value="false"/>
41+
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingFunctions" value="false"/>
42+
<property name="searchAnnotations" value="true"/>
43+
</properties>
44+
</rule>
45+
46+
47+
<!-- ****************************************************** -->
48+
<!-- Don't require annotations to specify traversable types -->
49+
<!-- ****************************************************** -->
50+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
51+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
52+
</rule>
53+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
54+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
55+
</rule>
56+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
57+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
58+
</rule>
59+
60+
61+
<!-- ************************************************************************** -->
62+
<!-- Require type hints for all parameters, properties, and return types in src -->
63+
<!-- ************************************************************************** -->
64+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint">
65+
<exclude-pattern>tests</exclude-pattern>
66+
</rule>
67+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint">
68+
<exclude-pattern>tests</exclude-pattern>
69+
</rule>
70+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint">
71+
<exclude-pattern>tests</exclude-pattern>
72+
</rule>
73+
74+
75+
<!-- *********************************************************** -->
76+
<!-- Require native type hints for all code without a BC promise -->
77+
<!-- *********************************************************** -->
78+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
79+
</rule>
80+
81+
82+
<!-- ************************************************************* -->
83+
<!-- Ignore errors for certain files where this is part of the API -->
84+
<!-- ************************************************************* -->
85+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
86+
</rule>
87+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
88+
</rule>
89+
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
90+
</rule>
91+
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
92+
</rule>
93+
</ruleset>

0 commit comments

Comments
 (0)