Skip to content

Commit

Permalink
add CONTRIBUTING file and pre_commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
James G Silva committed Feb 15, 2021
1 parent 7fd5da9 commit 4c9ec2d
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 113 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/phpunit.yml

This file was deleted.

13 changes: 11 additions & 2 deletions .github/workflows/phpstan.yml → .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHPStan
name: QA

on:
push:
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ composer.phar
/vendor/
.idea
.phpunit.result.cache
.php_cs.cache
.php_cs
.php_cs.cache
51 changes: 51 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

$finder = PhpCsFixer\Finder::create()
->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)
;
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
Expand All @@ -22,4 +22,8 @@ $kinesisHandler = new \JamesGSilva\MonologKinesisHandler\KinesisHandler($kinesis
$logger = new \Monolog\Logger('channel');
$logger->pushHandler($kinesisHandler);
$logger->info('Hello Kinesis');
```
```

## 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.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 7 additions & 31 deletions example/consumer.php → docs/examples/consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
25 changes: 25 additions & 0 deletions docs/examples/kinesis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

require '../vendor/autoload.php';

use Aws\Kinesis\KinesisClient;

$kineses = 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
]
]);

return $kineses;
20 changes: 20 additions & 0 deletions docs/examples/producer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require '../vendor/autoload.php';

use Aws\Kinesis\KinesisClient;
use Monolog\Logger;
use JamesGSilva\MonologKinesisHandler\KinesisHandler;

/** @var KinesisClient $kinesis */
$kinesis = require 'kinesis.php';
$shardCount = 2;
$streamName = 'my_stream_name';
$kinesis->createStream([
'ShardCount' => $shardCount,
'StreamName' => $streamName,
]);
$kinesisHandler = new KinesisHandler($kinesis, $streamName);
$logger = new Logger('logs');
$logger->pushHandler($kinesisHandler);
$logger->info('Hello Kinesis');
40 changes: 40 additions & 0 deletions docs/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env php
<?php

echo 'Run PHPCSFixer ' . PHP_EOL;
exec('composer run-script cs-check', $output, $returnCode);
if ($returnCode !== 0) {
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo 'Aborting commit by cs-check. Fix with composer cs-fix' . PHP_EOL;
exit(1);
}
echo $output[1] . PHP_EOL;

echo 'Run PHPCS ' . PHP_EOL;
exec('composer run-script phpcs', $output, $returnCode);
if ($returnCode !== 0) {
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo 'Aborting commit by phpcs' . PHP_EOL;
exit(1);
}
echo $output[2] . PHP_EOL;

echo 'Run PHPStan ' . PHP_EOL;
exec('composer run-script phpstan', $output, $returnCode);
if ($returnCode !== 0) {
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo 'Aborting commit by phpstan' . PHP_EOL;
exit(1);
}
echo $output[8] . ' - ' . $output[2] . PHP_EOL;

echo 'Run PHPUnit ' . PHP_EOL;
exec('composer run-script test', $output, $returnCode);
if ($returnCode !== 0) {
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo 'Aborting commit by tests' . PHP_EOL;
exit(1);
}
echo array_pop($output) . PHP_EOL;

exit(0);
39 changes: 0 additions & 39 deletions example/producer.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/KinesisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
class KinesisHandlerTest extends TestCase
{

/**
* This client is used to interact with the Amazon Kinesis service.
*
Expand Down

0 comments on commit 4c9ec2d

Please sign in to comment.