Skip to content

Commit

Permalink
Add php-cs-fixer as tool to project
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Zombaya committed Mar 27, 2023
1 parent 6359e46 commit 71fccec
Show file tree
Hide file tree
Showing 10 changed files with 2,151 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease/php-cs-fixer
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "",
"description": "Add php-cs-fixer as tool to format code and lint code according to PSR-12 during github actions"
}
]
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build/ export-ignore
docs/ export-ignore
tests/ export-ignore
tools/ export-ignore
features/ export-ignore
vendor/ export-ignore
.gitattributes export-ignore
Expand All @@ -13,6 +14,7 @@ composer.lock export-ignore
CONTRIBUTING.md export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
.php-cs-fixer.dist.php export-ignore
README.md export-ignore
UPGRADING.md export-ignore
src/data/*.json export-ignore
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,36 @@ jobs:
- if: ${{ (matrix.php-versions == '7.1' || matrix.php-versions == '8.0') && matrix.composer-options == '' }}
name: Code coverage
run: bash <(curl -s https://codecov.io/bash)

lint:
runs-on: ubuntu-20.04
name: Lint
steps:
#sets up the correct version of PHP with necessary config options
- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
ini-values: xdebug.overload_var_dump=0, memory_limit=4G, phar.readonly=false

#checkout the codebase from github
- name: Checkout codebase
uses: actions/checkout@v2

#get dependencies
- name: Install dependencies
run: composer update --working-dir=tools/php-cs-fixer --no-interaction

#run tests
- name: Lint codestyle using php-cs-fixer
run: >
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --verbose --dry-run || \
( echo -e "\n\n" \
&& echo "Problems with the formatting of the code have been detected." \
&& echo "You can manually fix these problems or run following commands to automatically fix these problems:" \
&& echo -e "\n" \
&& echo "composer install --working-dir=tools/php-cs-fixer" \
&& echo "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v" \
&& echo -e "\n\n" \
&& $(exit 1) # fail test \
)
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ test_services.json
.idea
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
atlassian-ide-plugin.xml
aws-sdk-php.iml
.DS_Store
.swp
.build
composer.lock
/composer.lock
vendor
docs/_build
docs/venv
Expand Down
29 changes: 29 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->exclude([
'data'
])
;

return (new PhpCsFixer\Config())
->setRules([
'@PER' => true,

// By default, visibility is required by PSR-12 for property, method and const.
// PHP >= 7.1 is required for const.
// Since we support PHP >= 5.5, the required visibility for const's is disabled.
// See https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/class_notation/visibility_required.rst
'visibility_required' => [
'elements' => [
'property',
'method',
],
]
])
->setFinder($finder)
;
11 changes: 8 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ we ask the same of all community contributions as well:
will be released under that license. For substantial contributions, we may
ask you to sign a [Contributor License Agreement (CLA)][cla].
2. We follow all of the relevant PSR recommendations from the [PHP Framework
Interop Group][php-fig]. Please submit code that follows these standards.
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code.
Interop Group][php-fig]. Please submit code that follows the
[PSR-12 standard](php-fig-psr12).
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code.
You can install the currently used version of PHP CS Fixer using
`composer install-cs-fix` and automatically format
your code by running `composer cs-fix`.
3. We maintain a high percentage of code coverage in our unit tests. If you make
changes to the code, please add, update, and/or remove tests as appropriate.
Tests are run via `make test` command.
Expand Down Expand Up @@ -152,7 +156,8 @@ category field should exist with the value set to an empty string `""`.
[pull-requests]: https://github.com/aws/aws-sdk-php/pulls
[license]: http://aws.amazon.com/apache2.0/
[cla]: https://github.com/aws/aws-cla/blob/master/amazon-single-contribution-license.txt
[php-fig]: http://php-fig.org
[php-fig]: https://www.php-fig.org/
[php-fig-psr12]: https://www.php-fig.org/psr/psr-12/
[cs-fixer]: http://cs.sensiolabs.org/
[phpstan]: https://github.com/phpstan/phpstan
[sphinx]: http://sphinx-doc.org/
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"yoast/phpunit-polyfills": "^1.0",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
},
"scripts": {
"install-cs-fix": "@composer install --working-dir=tools/php-cs-fixer",
"cs-fix": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v"
},
"suggest": {
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
"ext-curl": "To send requests using cURL",
Expand Down
1 change: 1 addition & 0 deletions tools/php-cs-fixer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.php-cs-fixer.cache
5 changes: 5 additions & 0 deletions tools/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"friendsofphp/php-cs-fixer": "^3.11.0"
}
}
Loading

0 comments on commit 71fccec

Please sign in to comment.