Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP CS Fixer as a formatting tool and lint-stage during github CI #2521

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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-cs-fix" \
&& echo "composer cs-fix" \
&& 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
[PER coding style](php-fig-per).
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-per]: https://www.php-fig.org/per/coding-style/
[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
5 changes: 4 additions & 1 deletion src/ACMPCA/ACMPCAClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\ACMPCA;

use Aws\AwsClient;
Expand Down Expand Up @@ -52,4 +53,6 @@
* @method \Aws\Result updateCertificateAuthority(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateCertificateAuthorityAsync(array $args = [])
*/
class ACMPCAClient extends AwsClient {}
class ACMPCAClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/ACMPCA/Exception/ACMPCAException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\ACMPCA\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **AWS Certificate Manager Private Certificate Authority** service.
*/
class ACMPCAException extends AwsException {}
class ACMPCAException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/ARCZonalShift/ARCZonalShiftClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\ARCZonalShift;

use Aws\AwsClient;
Expand All @@ -18,4 +19,6 @@
* @method \Aws\Result updateZonalShift(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateZonalShiftAsync(array $args = [])
*/
class ARCZonalShiftClient extends AwsClient {}
class ARCZonalShiftClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/ARCZonalShift/Exception/ARCZonalShiftException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\ARCZonalShift\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **AWS ARC - Zonal Shift** service.
*/
class ARCZonalShiftException extends AwsException {}
class ARCZonalShiftException extends AwsException
{
}
1 change: 1 addition & 0 deletions src/AbstractConfigurationProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws;

use GuzzleHttp\Promise;
Expand Down
5 changes: 4 additions & 1 deletion src/AccessAnalyzer/AccessAnalyzerClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\AccessAnalyzer;

use Aws\AwsClient;
Expand Down Expand Up @@ -62,4 +63,6 @@
* @method \Aws\Result validatePolicy(array $args = [])
* @method \GuzzleHttp\Promise\Promise validatePolicyAsync(array $args = [])
*/
class AccessAnalyzerClient extends AwsClient {}
class AccessAnalyzerClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/AccessAnalyzer/Exception/AccessAnalyzerException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\AccessAnalyzer\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **Access Analyzer** service.
*/
class AccessAnalyzerException extends AwsException {}
class AccessAnalyzerException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/Account/AccountClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\Account;

use Aws\AwsClient;
Expand All @@ -24,4 +25,6 @@
* @method \Aws\Result putContactInformation(array $args = [])
* @method \GuzzleHttp\Promise\Promise putContactInformationAsync(array $args = [])
*/
class AccountClient extends AwsClient {}
class AccountClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/Account/Exception/AccountException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\Account\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **AWS Account** service.
*/
class AccountException extends AwsException {}
class AccountException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/Acm/AcmClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\Acm;

use Aws\AwsClient;
Expand Down Expand Up @@ -37,4 +38,6 @@
* @method \Aws\Result updateCertificateOptions(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateCertificateOptionsAsync(array $args = [])
*/
class AcmClient extends AwsClient {}
class AcmClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/Acm/Exception/AcmException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\Acm\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **AWS Certificate Manager** service.
*/
class AcmException extends AwsException {}
class AcmException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/AlexaForBusiness/AlexaForBusinessClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\AlexaForBusiness;

use Aws\AwsClient;
Expand Down Expand Up @@ -192,4 +193,6 @@
* @method \Aws\Result updateSkillGroup(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateSkillGroupAsync(array $args = [])
*/
class AlexaForBusinessClient extends AwsClient {}
class AlexaForBusinessClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/AlexaForBusiness/Exception/AlexaForBusinessException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\AlexaForBusiness\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **Alexa For Business** service.
*/
class AlexaForBusinessException extends AwsException {}
class AlexaForBusinessException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/Amplify/AmplifyClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\Amplify;

use Aws\AwsClient;
Expand Down Expand Up @@ -80,4 +81,6 @@
* @method \Aws\Result updateWebhook(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateWebhookAsync(array $args = [])
*/
class AmplifyClient extends AwsClient {}
class AmplifyClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/Amplify/Exception/AmplifyException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\Amplify\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **AWS Amplify** service.
*/
class AmplifyException extends AwsException {}
class AmplifyException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/AmplifyBackend/AmplifyBackendClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\AmplifyBackend;

use Aws\AwsClient;
Expand Down Expand Up @@ -68,4 +69,6 @@
* @method \Aws\Result updateBackendStorage(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateBackendStorageAsync(array $args = [])
*/
class AmplifyBackendClient extends AwsClient {}
class AmplifyBackendClient extends AwsClient
{
}
5 changes: 4 additions & 1 deletion src/AmplifyBackend/Exception/AmplifyBackendException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace Aws\AmplifyBackend\Exception;

use Aws\Exception\AwsException;

/**
* Represents an error interacting with the **AmplifyBackend** service.
*/
class AmplifyBackendException extends AwsException {}
class AmplifyBackendException extends AwsException
{
}
5 changes: 4 additions & 1 deletion src/AmplifyUIBuilder/AmplifyUIBuilderClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aws\AmplifyUIBuilder;

use Aws\AwsClient;
Expand Down Expand Up @@ -50,4 +51,6 @@
* @method \Aws\Result updateTheme(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateThemeAsync(array $args = [])
*/
class AmplifyUIBuilderClient extends AwsClient {}
class AmplifyUIBuilderClient extends AwsClient
{
}
Loading