Skip to content

Commit

Permalink
Static analysis & Travis updates (#1861)
Browse files Browse the repository at this point in the history
* Add phpstan static analysis to travis config
* Add phpstan configuration
* Add PHP 7.4 to travis CI
* Config changes
* Add changelog
* Update contributing guidelines
  • Loading branch information
howardlopez committed Aug 1, 2019
1 parent 1bb860e commit c5c8eab
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease/static_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "",
"description": "Added static code analysis using PHPStan to Travis CI configuration."
}
]
42 changes: 38 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4
- hhvm
- nightly
env:
Expand All @@ -19,23 +20,56 @@ matrix:
allow_failures:
- php: hhvm
- php: nightly
- php: 7.4
fast_finish: true

sudo: false

install:
# Setup environment variables for testing
- export AWS_ACCESS_KEY_ID=foo
- export AWS_SECRET_ACCESS_KEY=bar
- export AWS_CSM_ENABLED=false
- 'if [ $(phpenv version-name) == "5.5" ]; then rm ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini; fi'
- 'if [ $(phpenv version-name) != "hhvm" ] && [ $(phpenv version-name) != "nightly" ]; then echo "xdebug.overload_var_dump = 0" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi'
- 'if { [ $(phpenv version-name) == "7.2" ] || [ $(phpenv version-name) == "7.3" ]; } && [ -v COMPOSER_OPTS ]; then composer require --dev phpunit/phpunit "^5.7.11"; fi'

# Build job specific tweaks
- >
if [ $(phpenv version-name) == "5.5" ]; then
rm ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
fi
- >
if [ $(phpenv version-name) != "hhvm" ] && [ $(phpenv version-name) != "nightly" ]; then
echo "xdebug.overload_var_dump = 0" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
fi
- >
if { [ $(phpenv version-name) == "7.2" ] || [ $(phpenv version-name) == "7.3" ]; } && [ -v COMPOSER_OPTS ]; then
composer require --dev phpunit/phpunit "^5.7.11"
fi
# Resolve dependencies
- composer --version
- travis_retry composer update $COMPOSER_OPTS --no-interaction --prefer-source

script:
# Unit tests
- make test

# Static analysis
- >
test_versions=("7.1" "7.2" "7.3" "7.4");
if [[ " ${test_versions[@]} " =~ " $(phpenv version-name) " ]] && [ -z $COMPOSER_OPTS ]; then
composer require --dev nette/neon "^3.0"
composer require --dev phpstan/phpstan
vendor/bin/phpstan analyse src
fi
# Package generation
- if [ -z "$COMPOSER_OPTS" ]; then make package; fi

after_success:
- 'if [ $(phpenv version-name) == "7.1" ]; then bash <(curl -s https://codecov.io/bash); fi'
# Code coverage report
- >
if [ $(phpenv version-name) == "7.1" ]; then
bash <(curl -s https://codecov.io/bash)
fi
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ your [issues][] or [pull requests][pull-requests] through GitHub.
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code.
1. 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.
1. Static code analysis with [PHPStan][phpstan] is automatically run on the `src`
directory for submitted pull requests. If there is a case that needs to be
ignored by static analysis, please update the `ignoreErrors` section in the
`phpstan.neon` config file in your PR, and point out why this case warrants
ignoring.
1. We may choose not to accept pull requests that change files in the `src/data`
directory, since we generate these files based on our internal knowledge of
the AWS services. Please check in with us ahead of time if you find a mistake
Expand Down Expand Up @@ -73,6 +78,7 @@ category field should exist with the value set to an empty string `""`.
[cla]: https://github.com/aws/aws-cla/blob/master/amazon-single-contribution-license.txt
[php-fig]: http://php-fig.org
[cs-fixer]: http://cs.sensiolabs.org/
[phpstan]: https://github.com/phpstan/phpstan
[sphinx]: http://sphinx-doc.org/
[restructuredtext]: http://sphinx-doc.org/rest.html
[docs-readme]: https://github.com/aws/aws-sdk-php/blob/master/docs/README.md
22 changes: 22 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
parameters:

level: 0

excludes_analyse:
# Guzzle V5 classes & interfaces changed in V6
- %rootDir%/../../../src/Handler/GuzzleV5/*

ignoreErrors:
# Intentional
- '#Aws\\Api\\Parser\\Crc32ValidatingParser::__construct\(\) does not call parent constructor from Aws\\Api\\Parser\\AbstractParser\.#'
- '#Aws\\S3\\(RetryableMalformedResponse|GetBucketLocation|AmbiguousSuccess)Parser::__construct\(\) does not call parent constructor from Aws\\Api\\Parser\\AbstractParser\.#'

# HashContext definition sometimes not found by static analysis
- '#Property Aws\\PhpHash::\$context has unknown class HashContext as its type\.#'
- '#Property Aws\\Api\\Parser\\DecodingEventStreamIterator::\$hashContext has unknown class HashContext as its type\.#'
- '#Return typehint of method Aws\\PhpHash::getContext\(\) has invalid type HashContext\.#'

# Guzzle V5 classes & interfaces changed in V6
- '#Call to an undefined static method GuzzleHttp\\Client::getDefaultUserAgent\(\)\.#'

reportUnmatchedIgnoredErrors: false

0 comments on commit c5c8eab

Please sign in to comment.