Skip to content

Commit 20e9748

Browse files
committed
Add php-cs-fixer as tool to project
Squashed commits ---------------- * fb76eba 2022-06-13 Zombaya Add php-cs-fixer as tool to project. Installed according to best practice in README of php-cs-fixer. * 549ceae 2022-06-14 Zombaya Add pipeline-check for valid codestyle using php-cs-fixer * 11812f2 2022-09-13 Zombaya Update CONTRIBUTING.md and set version of php-cs-fixer fixed to current latest version * 01cb480 2022-09-13 Zombaya Autoformat src and tests to PSR-12 using php-cs-fixer * e5e6e9599 2022-09-13 Zombaya Add release-file
1 parent 6359e46 commit 20e9748

File tree

10 files changed

+2151
-4
lines changed

10 files changed

+2151
-4
lines changed

.changes/nextrelease/php-cs-fixer

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"type": "enhancement",
4+
"category": "",
5+
"description": "Add php-cs-fixer as tool to format code and lint code according to PSR-12 during github actions"
6+
}
7+
]

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build/ export-ignore
22
docs/ export-ignore
33
tests/ export-ignore
4+
tools/ export-ignore
45
features/ export-ignore
56
vendor/ export-ignore
67
.gitattributes export-ignore
@@ -13,6 +14,7 @@ composer.lock export-ignore
1314
CONTRIBUTING.md export-ignore
1415
Makefile export-ignore
1516
phpunit.xml.dist export-ignore
17+
.php-cs-fixer.dist.php export-ignore
1618
README.md export-ignore
1719
UPGRADING.md export-ignore
1820
src/data/*.json export-ignore

.github/workflows/tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,36 @@ jobs:
8787
- if: ${{ (matrix.php-versions == '7.1' || matrix.php-versions == '8.0') && matrix.composer-options == '' }}
8888
name: Code coverage
8989
run: bash <(curl -s https://codecov.io/bash)
90+
91+
lint:
92+
runs-on: ubuntu-20.04
93+
name: Lint
94+
steps:
95+
#sets up the correct version of PHP with necessary config options
96+
- name: Setup PHP with Xdebug
97+
uses: shivammathur/setup-php@v2
98+
with:
99+
php-version: 8.1
100+
ini-values: xdebug.overload_var_dump=0, memory_limit=4G, phar.readonly=false
101+
102+
#checkout the codebase from github
103+
- name: Checkout codebase
104+
uses: actions/checkout@v2
105+
106+
#get dependencies
107+
- name: Install dependencies
108+
run: composer update --working-dir=tools/php-cs-fixer --no-interaction
109+
110+
#run tests
111+
- name: Lint codestyle using php-cs-fixer
112+
run: >
113+
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --verbose --dry-run || \
114+
( echo -e "\n\n" \
115+
&& echo "Problems with the formatting of the code have been detected." \
116+
&& echo "You can manually fix these problems or run following commands to automatically fix these problems:" \
117+
&& echo -e "\n" \
118+
&& echo "composer install --working-dir=tools/php-cs-fixer" \
119+
&& echo "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v" \
120+
&& echo -e "\n\n" \
121+
&& $(exit 1) # fail test \
122+
)

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ test_services.json
99
.idea
1010
.php_cs.cache
1111
.phpunit.result.cache
12+
.php-cs-fixer.cache
1213
atlassian-ide-plugin.xml
1314
aws-sdk-php.iml
1415
.DS_Store
1516
.swp
1617
.build
17-
composer.lock
18+
/composer.lock
1819
vendor
1920
docs/_build
2021
docs/venv

.php-cs-fixer.dist.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in([
5+
__DIR__ . '/src',
6+
__DIR__ . '/tests',
7+
])
8+
->exclude([
9+
'data'
10+
])
11+
;
12+
13+
return (new PhpCsFixer\Config())
14+
->setRules([
15+
'@PER' => true,
16+
17+
// By default, visibility is required by PSR-12 for property, method and const.
18+
// PHP >= 7.1 is required for const.
19+
// Since we support PHP >= 5.5, the required visibility for const's is disabled.
20+
// See https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/class_notation/visibility_required.rst
21+
'visibility_required' => [
22+
'elements' => [
23+
'property',
24+
'method',
25+
],
26+
]
27+
])
28+
->setFinder($finder)
29+
;

CONTRIBUTING.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ we ask the same of all community contributions as well:
8585
will be released under that license. For substantial contributions, we may
8686
ask you to sign a [Contributor License Agreement (CLA)][cla].
8787
2. We follow all of the relevant PSR recommendations from the [PHP Framework
88-
Interop Group][php-fig]. Please submit code that follows these standards.
89-
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code.
88+
Interop Group][php-fig]. Please submit code that follows the
89+
[PER coding style](php-fig-per).
90+
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code.
91+
You can install the currently used version of PHP CS Fixer using
92+
`composer install-cs-fix` and automatically format
93+
your code by running `composer cs-fix`.
9094
3. We maintain a high percentage of code coverage in our unit tests. If you make
9195
changes to the code, please add, update, and/or remove tests as appropriate.
9296
Tests are run via `make test` command.
@@ -152,7 +156,8 @@ category field should exist with the value set to an empty string `""`.
152156
[pull-requests]: https://github.com/aws/aws-sdk-php/pulls
153157
[license]: http://aws.amazon.com/apache2.0/
154158
[cla]: https://github.com/aws/aws-cla/blob/master/amazon-single-contribution-license.txt
155-
[php-fig]: http://php-fig.org
159+
[php-fig]: https://www.php-fig.org/
160+
[php-fig-per]: https://www.php-fig.org/per/coding-style/
156161
[cs-fixer]: http://cs.sensiolabs.org/
157162
[phpstan]: https://github.com/phpstan/phpstan
158163
[sphinx]: http://sphinx-doc.org/

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"yoast/phpunit-polyfills": "^1.0",
4646
"dms/phpunit-arraysubset-asserts": "^0.4.0"
4747
},
48+
"scripts": {
49+
"install-cs-fix": "@composer install --working-dir=tools/php-cs-fixer",
50+
"cs-fix": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v"
51+
},
4852
"suggest": {
4953
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
5054
"ext-curl": "To send requests using cURL",

tools/php-cs-fixer/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.php-cs-fixer.cache

tools/php-cs-fixer/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"friendsofphp/php-cs-fixer": "^3.11.0"
4+
}
5+
}

0 commit comments

Comments
 (0)