From 4c9ec2d5b9bd838144ac0d2e761d177454a82a0d Mon Sep 17 00:00:00 2001 From: James G Silva Date: Sun, 14 Feb 2021 21:13:09 -0300 Subject: [PATCH] add CONTRIBUTING file and pre_commit hook --- .github/workflows/phpunit.yml | 34 --------------- .github/workflows/{phpstan.yml => qa.yml} | 13 +++++- .gitignore | 3 +- .php_cs | 51 +++++++++++++++++++++++ CONTRIBUTING.md | 25 +++++++++++ README.md | 8 +++- composer.json | 7 ++-- {example => docs/examples}/consumer.php | 38 ++++------------- docs/examples/kinesis.php | 25 +++++++++++ docs/examples/producer.php | 20 +++++++++ docs/hooks/pre-commit | 40 ++++++++++++++++++ example/producer.php | 39 ----------------- tests/KinesisHandlerTest.php | 1 + 13 files changed, 191 insertions(+), 113 deletions(-) delete mode 100644 .github/workflows/phpunit.yml rename .github/workflows/{phpstan.yml => qa.yml} (73%) create mode 100644 .php_cs create mode 100644 CONTRIBUTING.md rename {example => docs/examples}/consumer.php (63%) create mode 100644 docs/examples/kinesis.php create mode 100644 docs/examples/producer.php create mode 100755 docs/hooks/pre-commit delete mode 100644 example/producer.php diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml deleted file mode 100644 index aab5125..0000000 --- a/.github/workflows/phpunit.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: PHPUnit - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v2 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - if: steps.composer-cache.outputs.cache-hit != 'true' - run: composer install --prefer-dist --no-progress --no-suggest - - - name: Run PHPUnit - run: composer run-script test diff --git a/.github/workflows/phpstan.yml b/.github/workflows/qa.yml similarity index 73% rename from .github/workflows/phpstan.yml rename to .github/workflows/qa.yml index 35cdb30..ddffef9 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/qa.yml @@ -1,4 +1,4 @@ -name: PHPStan +name: QA on: push: @@ -30,5 +30,14 @@ jobs: if: steps.composer-cache.outputs.cache-hit != 'true' run: composer install --prefer-dist --no-progress --no-suggest + - name: Run PHPCSFixer + run: composer run-script cs-check + + - name: Run PHPCS + run: composer run-script phpcs + - name: Run PHPStan - run: composer analyse + run: composer run-script phpstan + + - name: Run PHPUnit + run: composer run-script test diff --git a/.gitignore b/.gitignore index 2faf2d8..fdb4c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ composer.phar /vendor/ .idea .phpunit.result.cache -.php_cs.cache -.php_cs \ No newline at end of file +.php_cs.cache \ No newline at end of file diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..039c7d8 --- /dev/null +++ b/.php_cs @@ -0,0 +1,51 @@ +files() + ->name('*.php') + ->exclude('Fixtures') + ->in(__DIR__.'/src') + ->in(__DIR__.'/tests') +; + +return PhpCsFixer\Config::create() + ->setUsingCache(true) + ->setRiskyAllowed(true) + ->setRules(array( + '@PSR2' => true, + // some rules disabled as long as 1.x branch is maintained + 'binary_operator_spaces' => array( + 'default' => null, + ), + 'blank_line_before_statement' => ['statements' => ['continue', 'declare', 'return', 'throw', 'try']], + 'cast_spaces' => ['space' => 'single'], + 'include' => true, + 'class_attributes_separation' => ['elements' => ['method']], + 'no_blank_lines_after_class_opening' => false, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unused_imports' => true, + 'no_whitespace_in_blank_line' => true, + 'object_operator_without_whitespace' => true, + 'phpdoc_align' => true, + 'phpdoc_indent' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_package' => true, + 'phpdoc_order' => true, + //'phpdoc_scalar' => true, + 'phpdoc_trim' => true, + //'phpdoc_types' => true, + 'psr0' => true, + //'array_syntax' => array('syntax' => 'short'), + 'declare_strict_types' => true, + 'single_blank_line_before_namespace' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline_array' => true, + )) + ->setFinder($finder) +; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..f438ea1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,25 @@ +# Contributing + +Thank you for your interest in contributing to our `monolog-kinesis-handler`! + +## Before submitting a pull request + +- Add git hooks running `cp docs/hooks/pre-commit .git/hooks` +- Check Coding Standards running `composer run-script cs-check` +- Fix Coding Standards running `composer run-script cs-fix` +- Statically analysis running `composer run-script phpstan` +- Detects coding standards violations running `composer run-script phpcs` +- Test running `composer run-script test` + +## Submitting a pull request + +1. [Fork](https://github.com/jamesgsilva/monolog-kinesis-handler/fork) and clone the repository; +1. Create a new branch: `git checkout -b my-branch-name`; +1. Make your change, push to your fork and [submit a pull request](https://github.com/jamesgsilva/monolog-kinesis-handler/compare); +1. Pat your self on the back and wait for your pull request to be reviewed. + +## Resources + +- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) +- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) +- [GitHub Help](https://help.github.com) \ No newline at end of file diff --git a/README.md b/README.md index a4d5749..ffbd2e9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ $ composer require jamesgsilva/monolog-kinesis-handler ## Usage -You can find usage example [here](example) using [kinesalite](https://github.com/mhart/kinesalite) an implementation of Amazon's Kinesis built on LevelDB. +You can find usage examples [here](docs/examples) using [kinesalite](https://github.com/mhart/kinesalite) an implementation of Amazon's Kinesis built on LevelDB. ```php pushHandler($kinesisHandler); $logger->info('Hello Kinesis'); -``` \ No newline at end of file +``` + +## Contributing + +Feel free to contribute by opening a pull request. Bug fixes or feature suggestions are always welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for information. \ No newline at end of file diff --git a/composer.json b/composer.json index c1bf44b..419485d 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,10 @@ ], "scripts": { "test": "vendor/bin/phpunit tests", - "fix": "vendor/bin/php-cs-fixer fix", - "analyse": "vendor/bin/phpstan analyse", - "check": "vendor/bin/phpcs" + "cs-check": "vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs", + "cs-fix": "vendor/bin/php-cs-fixer fix --diff --config=.php_cs", + "phpstan": "vendor/bin/phpstan analyse", + "phpcs": "vendor/bin/phpcs" }, "require": { "php": ">=7.2", diff --git a/example/consumer.php b/docs/examples/consumer.php similarity index 63% rename from example/consumer.php rename to docs/examples/consumer.php index b780bd0..4d31cff 100644 --- a/example/consumer.php +++ b/docs/examples/consumer.php @@ -2,38 +2,14 @@ require '../vendor/autoload.php'; -use Aws\Kinesis\KinesisClient; -use Monolog\Logger; -use JamesGSilva\MonologKinesisHandler\KinesisHandler; - -$kinesis = new KinesisClient([ - 'endpoint' => 'http://localhost:4567', - 'region' => 'us-west-2', - 'version' => 'latest', - 'credentials' => [ - 'key' => 'YOUR_AWS_ACCESS_KEY_ID', - 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', - ], - 'retries' => 10, - 'delay' => 1000, - 'synchronous' => true, - 'http' => [ - 'timeout' => 5, - 'connect_timeout' => 5, - 'verify' => false - ] -]); +/** @var \Aws\Kinesis\KinesisClient $kinesis */ +$kinesis = require 'kinesis.php'; $shardCount = 2; $streamName = 'my_stream_name'; -try { - $kinesis->createStream([ - 'ShardCount' => $shardCount, - 'StreamName' => $streamName, - ]); -} catch (\Throwable $e) { - echo $e->getMessage(), PHP_EOL; -} - +$kinesis->createStream([ + 'ShardCount' => $shardCount, + 'StreamName' => $streamName, +]); $numberOfRecordsPerBatch = 10; $res = $kinesis->describeStream([ 'StreamName' => $streamName ]); $shardIds = $res->search('StreamDescription.Shards[].ShardId'); @@ -43,7 +19,7 @@ echo "ShardId: $shardId\n"; $res = $kinesis->getShardIterator([ 'ShardId' => $shardId, - 'ShardIteratorType' => 'TRIM_HORIZON', // 'AT_SEQUENCE_NUMBER|AFTER_SEQUENCE_NUMBER|TRIM_HORIZON|LATEST' + 'ShardIteratorType' => 'TRIM_HORIZON', 'StreamName' => $streamName, ]); $shardIterator = $res->get('ShardIterator'); diff --git a/docs/examples/kinesis.php b/docs/examples/kinesis.php new file mode 100644 index 0000000..4b9ac9a --- /dev/null +++ b/docs/examples/kinesis.php @@ -0,0 +1,25 @@ + 'http://localhost:4567', + 'region' => 'us-west-2', + 'version' => 'latest', + 'credentials' => [ + 'key' => 'YOUR_AWS_ACCESS_KEY_ID', + 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', + ], + 'retries' => 10, + 'delay' => 1000, + 'synchronous' => true, + 'http' => [ + 'timeout' => 5, + 'connect_timeout' => 5, + 'verify' => false + ] +]); + +return $kineses; \ No newline at end of file diff --git a/docs/examples/producer.php b/docs/examples/producer.php new file mode 100644 index 0000000..ed617a2 --- /dev/null +++ b/docs/examples/producer.php @@ -0,0 +1,20 @@ +createStream([ + 'ShardCount' => $shardCount, + 'StreamName' => $streamName, +]); +$kinesisHandler = new KinesisHandler($kinesis, $streamName); +$logger = new Logger('logs'); +$logger->pushHandler($kinesisHandler); +$logger->info('Hello Kinesis'); \ No newline at end of file diff --git a/docs/hooks/pre-commit b/docs/hooks/pre-commit new file mode 100755 index 0000000..0aa29d9 --- /dev/null +++ b/docs/hooks/pre-commit @@ -0,0 +1,40 @@ +#!/usr/bin/env php + 'http://localhost:4567', //https://github.com/mhart/kinesalite - 'region' => 'us-west-2', - 'version' => 'latest', - 'credentials' => [ - 'key' => 'YOUR_AWS_ACCESS_KEY_ID', - 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', - ], - 'retries' => 10, - 'delay' => 1000, - 'synchronous' => true, - 'http' => [ - 'timeout' => 5, - 'connect_timeout' => 5, - 'verify' => false - ] -]); -$shardCount = 2; -$streamName = 'my_stream_name'; -try { - $kinesis->createStream([ - 'ShardCount' => $shardCount, - 'StreamName' => $streamName, - ]); -} catch (\Throwable $e) { - echo $e->getMessage(), PHP_EOL; -} -$kinesisHandler = new KinesisHandler($kinesis, $streamName); -$logger = new Logger('logs'); -$logger->pushHandler($kinesisHandler); -$logger->info('Hello Kinesis'); \ No newline at end of file diff --git a/tests/KinesisHandlerTest.php b/tests/KinesisHandlerTest.php index e5fe90e..d2ec7df 100644 --- a/tests/KinesisHandlerTest.php +++ b/tests/KinesisHandlerTest.php @@ -15,6 +15,7 @@ */ class KinesisHandlerTest extends TestCase { + /** * This client is used to interact with the Amazon Kinesis service. *