Skip to content

Commit 61adb96

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

File tree

5 files changed

+92
-210
lines changed

5 files changed

+92
-210
lines changed

.github/workflows/build-ci.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,6 @@ on:
77
pull_request:
88

99
jobs:
10-
php-cs-fixer:
11-
runs-on: ubuntu-latest
12-
env:
13-
PHP_CS_FIXER_VERSION: v3.6.0
14-
strategy:
15-
matrix:
16-
php:
17-
- '8.1'
18-
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v3
21-
- name: Setup PHP
22-
uses: shivammathur/setup-php@v2
23-
with:
24-
php-version: ${{ matrix.php }}
25-
extensions: curl,mbstring
26-
tools: php-cs-fixer:${{ env.PHP_CS_FIXER_VERSION }}
27-
coverage: none
28-
- name: Run PHP-CS-Fixer Fix, version ${{ env.PHP_CS_FIXER_VERSION }}
29-
run: php-cs-fixer fix --dry-run --diff --ansi
30-
3110
build:
3211
runs-on: ${{ matrix.os }}
3312
name: PHP v${{ matrix.php }} with MongoDB ${{ matrix.mongodb }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: "Coding Standards"
2+
3+
on:
4+
push:
5+
branches:
6+
tags:
7+
pull_request:
8+
9+
env:
10+
PHP_VERSION: "8.2"
11+
DRIVER_VERSION: "stable"
12+
13+
jobs:
14+
phpcs:
15+
name: "phpcs"
16+
runs-on: "ubuntu-22.04"
17+
18+
steps:
19+
- name: "Checkout"
20+
uses: "actions/checkout@v3"
21+
22+
- name: Setup cache environment
23+
id: extcache
24+
uses: shivammathur/cache-extensions@v1
25+
with:
26+
php-version: ${{ env.PHP_VERSION }}
27+
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
28+
key: "extcache-v1"
29+
30+
- name: Cache extensions
31+
uses: actions/cache@v3
32+
with:
33+
path: ${{ steps.extcache.outputs.dir }}
34+
key: ${{ steps.extcache.outputs.key }}
35+
restore-keys: ${{ steps.extcache.outputs.key }}
36+
37+
- name: "Install PHP"
38+
uses: "shivammathur/setup-php@v2"
39+
with:
40+
coverage: "none"
41+
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
42+
php-version: "${{ env.PHP_VERSION }}"
43+
tools: "cs2pr"
44+
45+
- name: "Show driver information"
46+
run: "php --ri mongodb"
47+
48+
- name: "Install dependencies with Composer"
49+
uses: "ramsey/composer-install@2.2.0"
50+
with:
51+
composer-options: "--no-suggest"
52+
53+
# The -q option is required until phpcs v4 is released
54+
- name: "Run PHP_CodeSniffer"
55+
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.UselessIfCondition"/>
23+
<exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing"/>
24+
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
25+
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
26+
<exclude name="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>
27+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
28+
</rule>
29+
</ruleset>

0 commit comments

Comments
 (0)