From 5626d178db73c1c2b0436302296de4d7138a68b7 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jan 2024 22:47:11 +0100 Subject: [PATCH 1/7] Add Pr0gramm Channel --- .editorconfig | 15 ++++ .gitattributes | 10 +++ .github/workflows/tests.yml | 32 ++++++++ .gitignore | 6 ++ .scrutinizer.yml | 21 +++++ .styleci.yml | 1 + CHANGELOG.md | 7 ++ CONTRIBUTING.md | 55 +++++++++++++ LICENSE.md | 21 +++++ README.md | 85 ++++++++++++++++++--- composer.json | 49 ++++++++++++ phpunit.xml.dist | 29 +++++++ src/Exceptions/CouldNotSendNotification.php | 35 +++++++++ src/Exceptions/Pr0grammRateLimitReached.php | 15 ++++ src/Pr0grammChannel.php | 57 ++++++++++++++ src/Pr0grammServiceProvider.php | 28 +++++++ tests/Pr0grammTest.php | 14 ++++ 17 files changed, 468 insertions(+), 12 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 .scrutinizer.yml create mode 100644 .styleci.yml create mode 100755 CHANGELOG.md create mode 100755 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/Exceptions/CouldNotSendNotification.php create mode 100644 src/Exceptions/Pr0grammRateLimitReached.php create mode 100644 src/Pr0grammChannel.php create mode 100644 src/Pr0grammServiceProvider.php create mode 100644 tests/Pr0grammTest.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..cd8eb86e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..b2638710 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/.scrutinizer.yml export-ignore +/tests export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..f9ff88d2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,32 @@ +name: PHPUnit tests + +on: + - push + - pull_request + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [7.2, 7.3, 7.4, 8.0] + + name: Tests on PHP ${{ matrix.php }} - ${{ matrix.stability }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: composer update --prefer-source --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit --verbose diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..616e6d3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/vendor +build +composer.phar +composer.lock +.DS_Store +.phpunit.result.cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 00000000..6fad5be9 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,21 @@ +filter: + excluded_paths: [tests/*] + +checks: + php: + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true + +tools: + external_code_coverage: true diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000..0285f179 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: laravel diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 00000000..a3bce087 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to `pr0gramm` will be documented in this file + +## 1.0.0 - 201X-XX-XX + +- initial release diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100755 index 00000000..4da74e3f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..9d5c31fe --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) Marcel Wagner + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/README.md b/README.md index fa8362b7..651bbc07 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,78 @@ -# New Notification Channels +Please see [this repo](https://github.com/laravel-notification-channels/channels) for instructions on how to submit a channel proposal. -### Suggesting a new channel -Have a suggestion or working on a new channel? Please create a new issue for that service. +# A Boilerplate repo for contributions -### I'm working on a new channel -Please create an issue for it if it does not already exist, then PR you code for review. +[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/pr0gramm.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pr0gramm) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) +[![Build Status](https://img.shields.io/travis/laravel-notification-channels/pr0gramm/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/pr0gramm) +[![StyleCI](https://styleci.io/repos/:style_ci_id/shield)](https://styleci.io/repos/:style_ci_id) +[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/:sensio_labs_id.svg?style=flat-square)](https://insight.sensiolabs.com/projects/:sensio_labs_id) +[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/pr0gramm.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/pr0gramm) +[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/pr0gramm/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/pr0gramm/?branch=master) +[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/pr0gramm.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pr0gramm) -## Workflow for new channels +This package makes it easy to send notifications using [Pr0gramm](link to service) with Laravel 5.5+, 6.x and 7.x -1) Head over to the [skeleton repo](https://github.com/laravel-notification-channels/skeleton) download a ZIP copy. This is important, to ensure you start from a fresh commit history. -2) Use find/replace to replace all of the placeholders with the correct values (package name, author name, email, etc). -3) Implement to logic for the channel & add tests. -4) Fork this repo, add it as a remote and push your new channel to a branch. -5) Submit a new PR against this repo for review. +**Note:** Replace ```Pr0gramm``` ```Pr0gramm``` ```Marcel Wagner``` ```Tschucki``` ```:https://www.marcelwagner.dev/``` ```info@marcelwagner.dev``` ```pr0gramm``` ```Laravel notification driver for Pr0gramm.``` ```:style_ci_id``` ```:sensio_labs_id``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md), [composer.json](composer.json) and other files, then delete this line. +**Tip:** Use "Find in Path/Files" in your code editor to find these keywords within the package directory and replace all occurences with your specified term. -Take a look at our [FAQ](http://laravel-notification-channels.com/) to see our small list of rules, to provide top-notch notification channels. +This is where your description should go. Add a little code example so build can understand real quick how the package can be used. Try and limit it to a paragraph or two. + + + +## Contents + +- [Installation](#installation) + - [Setting up the Pr0gramm service](#setting-up-the-Pr0gramm-service) +- [Usage](#usage) + - [Available Message methods](#available-message-methods) +- [Changelog](#changelog) +- [Testing](#testing) +- [Security](#security) +- [Contributing](#contributing) +- [Credits](#credits) +- [License](#license) + + +## Installation + +Please also include the steps for any third-party service setup that's required for this package. + +### Setting up the Pr0gramm service + +Optionally include a few steps how users can set up the service. + +## Usage + +Some code examples, make it clear how to use the package + +### Available Message methods + +A list of all available options + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Testing + +``` bash +$ composer test +``` + +## Security + +If you discover any security related issues, please email info@marcelwagner.dev instead of using the issue tracker. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Credits + +- [Marcel Wagner](https://github.com/Tschucki) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..f69e0390 --- /dev/null +++ b/composer.json @@ -0,0 +1,49 @@ +{ + "name": "laravel-notification-channels/pr0gramm", + "description": "Laravel notification driver for Pr0gramm.", + "homepage": "https://github.com/laravel-notification-channels/pr0gramm", + "license": "MIT", + "version": "0.0.1", + "keywords": [ + "laravel", + "notification", + "driver", + "channel", + "pr0gramm" + ], + "authors": [ + { + "name": "Marcel Wagner", + "email": "info@marcelwagner.dev", + "homepage": "https://www.marcelwagner.dev/", + "role": "Developer" + } + ], + "require": { + "php": ">=7.2", + "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "tschucki/laravel-pr0gramm-api": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^9.0" + }, + "autoload": { + "psr-4": { + "NotificationChannels\\Pr0gramm\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "NotificationChannels\\Pr0gramm\\Test\\": "tests" + } + }, + "scripts": { + "test": "phpunit", + "test:coverage": "phpunit --coverage-text --coverage-clover=coverage.clover" + }, + "config": { + "sort-packages": true + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..76608559 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + tests + + + + + src/ + + + + + + + + + + diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php new file mode 100644 index 00000000..3703b9fa --- /dev/null +++ b/src/Exceptions/CouldNotSendNotification.php @@ -0,0 +1,35 @@ +toPr0gramm($notifiable); + + if (!is_string($message)) { + throw CouldNotSendNotification::noStringForMessageProvided(); + } + + $response = Pr0grammApi::Inbox()->post($message, $notifiable->getPr0grammName()); + + if ($response->failed()) { + throw CouldNotSendNotification::serviceRespondedWithAnError($response->body()); + } + + if ($response->status() === 429) { + throw Pr0grammRateLimitReached::rateLimitReached(); + } + + } +} diff --git a/src/Pr0grammServiceProvider.php b/src/Pr0grammServiceProvider.php new file mode 100644 index 00000000..20a8732a --- /dev/null +++ b/src/Pr0grammServiceProvider.php @@ -0,0 +1,28 @@ +app->when(Pr0grammChannel::class) + ->needs(Pr0grammApi::class) + ->give(function () { + return Pr0grammApi::class; + }); + + } + + public function register(): void + { + Notification::resolved(static function (ChannelManager $service) { + $service->extend('pr0gramm', static fn ($app) => $app->make(Pr0grammChannel::class)); + }); + } +} diff --git a/tests/Pr0grammTest.php b/tests/Pr0grammTest.php new file mode 100644 index 00000000..4c1549df --- /dev/null +++ b/tests/Pr0grammTest.php @@ -0,0 +1,14 @@ +assertTrue(true); + } +} From dbc25b99616cd6ead7ac0d7f74bcdfea7b2526f8 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jan 2024 23:08:39 +0100 Subject: [PATCH 2/7] Update README --- README.md | 79 +++++++++++++++++++++++++++++++++++++++------------ composer.json | 2 +- 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 651bbc07..2e9a0c5a 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,20 @@ -Please see [this repo](https://github.com/laravel-notification-channels/channels) for instructions on how to submit a channel proposal. - -# A Boilerplate repo for contributions +# Pr0gramm Laravel Notifications Channel [![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/pr0gramm.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pr0gramm) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://img.shields.io/travis/laravel-notification-channels/pr0gramm/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/pr0gramm) [![StyleCI](https://styleci.io/repos/:style_ci_id/shield)](https://styleci.io/repos/:style_ci_id) -[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/:sensio_labs_id.svg?style=flat-square)](https://insight.sensiolabs.com/projects/:sensio_labs_id) [![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/pr0gramm.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/pr0gramm) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/pr0gramm/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/pr0gramm/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/pr0gramm.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pr0gramm) -This package makes it easy to send notifications using [Pr0gramm](link to service) with Laravel 5.5+, 6.x and 7.x - -**Note:** Replace ```Pr0gramm``` ```Pr0gramm``` ```Marcel Wagner``` ```Tschucki``` ```:https://www.marcelwagner.dev/``` ```info@marcelwagner.dev``` ```pr0gramm``` ```Laravel notification driver for Pr0gramm.``` ```:style_ci_id``` ```:sensio_labs_id``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md), [composer.json](composer.json) and other files, then delete this line. -**Tip:** Use "Find in Path/Files" in your code editor to find these keywords within the package directory and replace all occurences with your specified term. - -This is where your description should go. Add a little code example so build can understand real quick how the package can be used. Try and limit it to a paragraph or two. - - +This package makes it easy to send notifications to [Pr0gramm](https://pr0gramm.com/) users with Laravel. ## Contents - [Installation](#installation) - [Setting up the Pr0gramm service](#setting-up-the-Pr0gramm-service) - [Usage](#usage) - - [Available Message methods](#available-message-methods) - [Changelog](#changelog) - [Testing](#testing) - [Security](#security) @@ -36,19 +25,73 @@ This is where your description should go. Add a little code example so build can ## Installation -Please also include the steps for any third-party service setup that's required for this package. +You can install the package via composer: + +```bash +composer require laravel-notification-channels/pr0gramm +``` + +Next, you must load the service provider if you don't use auto-discovery: + +```php +// config/app.php +'providers' => [ + // ... + NotificationChannels\Pr0gramm\Pr0grammServiceProvider::class, +], +``` ### Setting up the Pr0gramm service -Optionally include a few steps how users can set up the service. +It is recommended to use the credentials of a bot account, as you will not be able to solve the required captcha. You can read more about the Pr0gramm-API and how to get your credentials [here](https://github.com/pr0gramm-com/api-docs/). + +Next, you must add your Pr0gramm Credentials in `config/services.php`: + +```php +// config/services.php +'pr0gramm' => [ + 'username' => env('PR0GRAMM_USERNAME'), + 'password' => env('PR0GRAMM_PASSWORD'), +], +``` ## Usage -Some code examples, make it clear how to use the package +In every model you wish to be notifiable via Pr0gramm, you must add a `getPr0grammName` method that returns the name of the user on Pr0gramm. + +```php +// app/Models/User.php +public function getPr0grammName(): string +{ + return $this->pr0grammName; +} +``` + +You can now use the channel in your `via()` method inside the notification (You can also use `'pr0gramm'` as channel name)): + +```php +use NotificationChannels\Pr0gramm\Pr0grammChannel; + +public function via($notifiable) +{ + return [Pr0grammChannel::class]; +} +``` + +Next, you must add a `toPr0gramm` method to your notification containing the message you wish to send to the user: + +```php +public function toPr0gramm($notifiable): string +{ + return 'Message from Laravel'; +} +``` -### Available Message methods +> **NOTE - RATE LIMIT**: As the rate limit for sending messages is quite low, you will probably run into the `Pr0grammRateLimitReached`-Exception. +> +> You can handle this exception through your try catch block or when using the queue driver by adding a `failed`-method to your notification and release the job again. -A list of all available options +That's it, you're ready to go! ## Changelog diff --git a/composer.json b/composer.json index f69e0390..7c4d2fe5 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": ">=7.2", "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "tschucki/laravel-pr0gramm-api": "^1.0" + "tschucki/laravel-pr0gramm-api": "^1.0.0" }, "require-dev": { "mockery/mockery": "^1.0", From 56b0cc279afbbea26e5b6107e4d6653e2452234f Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jan 2024 23:21:12 +0100 Subject: [PATCH 3/7] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c4d2fe5..f69e0390 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": ">=7.2", "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "tschucki/laravel-pr0gramm-api": "^1.0.0" + "tschucki/laravel-pr0gramm-api": "^1.0" }, "require-dev": { "mockery/mockery": "^1.0", From 44bfba3164e583c641ceecdff281cbb78917498f Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jan 2024 23:22:33 +0100 Subject: [PATCH 4/7] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f69e0390..b1270ff4 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": ">=7.2", "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "tschucki/laravel-pr0gramm-api": "^1.0" + "tschucki/laravel-pr0gramm-api": "1.0.4" }, "require-dev": { "mockery/mockery": "^1.0", From 8cca5ee756eed05b4984670bdbf1da466f8bb529 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jan 2024 23:24:32 +0100 Subject: [PATCH 5/7] Update php requirements --- .github/workflows/tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f9ff88d2..6199a818 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4, 8.0] + php: [8.1] name: Tests on PHP ${{ matrix.php }} - ${{ matrix.stability }} diff --git a/composer.json b/composer.json index b1270ff4..53228b56 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=8.1", "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", "tschucki/laravel-pr0gramm-api": "1.0.4" From 44ef2c3c691a5c8f54b0d1bc55f8a6a34062ffaf Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 14 Jan 2024 00:05:20 +0100 Subject: [PATCH 6/7] Reformat Code --- .github/workflows/tests.yml | 2 +- .scrutinizer.yml | 32 +++---- CONTRIBUTING.md | 18 ++-- README.md | 18 ++-- composer.json | 93 +++++++++++---------- src/Exceptions/CouldNotSendNotification.php | 6 +- src/Exceptions/Pr0grammRateLimitReached.php | 6 +- src/Pr0grammChannel.php | 7 +- src/Pr0grammServiceProvider.php | 3 +- 9 files changed, 96 insertions(+), 89 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6199a818..2ad24a45 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.1] + php: [ 8.1 ] name: Tests on PHP ${{ matrix.php }} - ${{ matrix.stability }} diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 6fad5be9..db54c400 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,21 +1,21 @@ filter: - excluded_paths: [tests/*] + excluded_paths: [ tests/* ] checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true + php: + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true tools: - external_code_coverage: true + external_code_coverage: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4da74e3f..1443ce01 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,8 @@ Please be considerate towards maintainers when raising issues or presenting pull world that developers are civilized and selfless people. It's the duty of the maintainer to ensure that all submissions to the project are of sufficient -quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the +maintainer's decision, and do not be upset or abusive if your submission is not used. ## Viability @@ -40,16 +41,23 @@ Before submitting a pull request: If the project maintainer has any additional requirements, you will find them listed here. -- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) + ** - The easiest way to apply the conventions is to + install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). - **Add tests!** - Your patch won't be accepted if it doesn't have tests. -- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept + up-to-date. -- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs + is not an option. - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. -- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make + multiple intermediate commits while developing, + please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) + before submitting. **Happy coding**! diff --git a/README.md b/README.md index 2e9a0c5a..eb6e6422 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This package makes it easy to send notifications to [Pr0gramm](https://pr0gramm. ## Contents - [Installation](#installation) - - [Setting up the Pr0gramm service](#setting-up-the-Pr0gramm-service) + - [Setting up the Pr0gramm service](#setting-up-the-Pr0gramm-service) - [Usage](#usage) - [Changelog](#changelog) - [Testing](#testing) @@ -22,7 +22,6 @@ This package makes it easy to send notifications to [Pr0gramm](https://pr0gramm. - [Credits](#credits) - [License](#license) - ## Installation You can install the package via composer: @@ -43,7 +42,8 @@ Next, you must load the service provider if you don't use auto-discovery: ### Setting up the Pr0gramm service -It is recommended to use the credentials of a bot account, as you will not be able to solve the required captcha. You can read more about the Pr0gramm-API and how to get your credentials [here](https://github.com/pr0gramm-com/api-docs/). +It is recommended to use the credentials of a bot account, as you will not be able to solve the required captcha. You +can read more about the Pr0gramm-API and how to get your credentials [here](https://github.com/pr0gramm-com/api-docs/). Next, you must add your Pr0gramm Credentials in `config/services.php`: @@ -57,7 +57,8 @@ Next, you must add your Pr0gramm Credentials in `config/services.php`: ## Usage -In every model you wish to be notifiable via Pr0gramm, you must add a `getPr0grammName` method that returns the name of the user on Pr0gramm. +In every model you wish to be notifiable via Pr0gramm, you must add a `getPr0grammName` method that returns the name of +the user on Pr0gramm. ```php // app/Models/User.php @@ -67,7 +68,8 @@ public function getPr0grammName(): string } ``` -You can now use the channel in your `via()` method inside the notification (You can also use `'pr0gramm'` as channel name)): +You can now use the channel in your `via()` method inside the notification (You can also use `'pr0gramm'` as channel +name)): ```php use NotificationChannels\Pr0gramm\Pr0grammChannel; @@ -87,9 +89,11 @@ public function toPr0gramm($notifiable): string } ``` -> **NOTE - RATE LIMIT**: As the rate limit for sending messages is quite low, you will probably run into the `Pr0grammRateLimitReached`-Exception. +> **NOTE - RATE LIMIT**: As the rate limit for sending messages is quite low, you will probably run into +> the `Pr0grammRateLimitReached`-Exception. > -> You can handle this exception through your try catch block or when using the queue driver by adding a `failed`-method to your notification and release the job again. +> You can handle this exception through your try catch block or when using the queue driver by adding a `failed`-method +> to your notification and release the job again. That's it, you're ready to go! diff --git a/composer.json b/composer.json index 53228b56..a42fd1b7 100644 --- a/composer.json +++ b/composer.json @@ -1,49 +1,50 @@ { - "name": "laravel-notification-channels/pr0gramm", - "description": "Laravel notification driver for Pr0gramm.", - "homepage": "https://github.com/laravel-notification-channels/pr0gramm", - "license": "MIT", - "version": "0.0.1", - "keywords": [ - "laravel", - "notification", - "driver", - "channel", - "pr0gramm" - ], - "authors": [ - { - "name": "Marcel Wagner", - "email": "info@marcelwagner.dev", - "homepage": "https://www.marcelwagner.dev/", - "role": "Developer" - } - ], - "require": { - "php": ">=8.1", - "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "tschucki/laravel-pr0gramm-api": "1.0.4" - }, - "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^9.0" - }, - "autoload": { - "psr-4": { - "NotificationChannels\\Pr0gramm\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "NotificationChannels\\Pr0gramm\\Test\\": "tests" - } - }, - "scripts": { - "test": "phpunit", - "test:coverage": "phpunit --coverage-text --coverage-clover=coverage.clover" - }, - "config": { - "sort-packages": true + "name": "laravel-notification-channels/pr0gramm", + "description": "Laravel notification driver for Pr0gramm.", + "homepage": "https://github.com/laravel-notification-channels/pr0gramm", + "license": "MIT", + "version": "0.0.1", + "keywords": [ + "laravel", + "notification", + "driver", + "channel", + "pr0gramm" + ], + "authors": [ + { + "name": "Marcel Wagner", + "email": "info@marcelwagner.dev", + "homepage": "https://www.marcelwagner.dev/", + "role": "Developer" } + ], + "require": { + "php": ">=8.1", + "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "tschucki/laravel-pr0gramm-api": "1.0.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.46", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^9.0" + }, + "autoload": { + "psr-4": { + "NotificationChannels\\Pr0gramm\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "NotificationChannels\\Pr0gramm\\Test\\": "tests" + } + }, + "scripts": { + "test": "phpunit", + "test:coverage": "phpunit --coverage-text --coverage-clover=coverage.clover" + }, + "config": { + "sort-packages": true + } } diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php index 3703b9fa..2b04c2d6 100644 --- a/src/Exceptions/CouldNotSendNotification.php +++ b/src/Exceptions/CouldNotSendNotification.php @@ -2,11 +2,9 @@ namespace NotificationChannels\Pr0gramm\Exceptions; -use Spatie\Ignition\Contracts\BaseSolution; -use Spatie\Ignition\Contracts\ProvidesSolution; -use Spatie\Ignition\Contracts\Solution; +use Exception; -class CouldNotSendNotification extends \Exception +class CouldNotSendNotification extends Exception { public static function serviceRespondedWithAnError($body): static { diff --git a/src/Exceptions/Pr0grammRateLimitReached.php b/src/Exceptions/Pr0grammRateLimitReached.php index acc4fc59..228fd75d 100644 --- a/src/Exceptions/Pr0grammRateLimitReached.php +++ b/src/Exceptions/Pr0grammRateLimitReached.php @@ -2,11 +2,9 @@ namespace NotificationChannels\Pr0gramm\Exceptions; -use Spatie\Ignition\Contracts\BaseSolution; -use Spatie\Ignition\Contracts\ProvidesSolution; -use Spatie\Ignition\Contracts\Solution; +use Exception; -class Pr0grammRateLimitReached extends \Exception +class Pr0grammRateLimitReached extends Exception { public static function rateLimitReached(): static { diff --git a/src/Pr0grammChannel.php b/src/Pr0grammChannel.php index 2676c5fd..a53e20b0 100644 --- a/src/Pr0grammChannel.php +++ b/src/Pr0grammChannel.php @@ -3,8 +3,8 @@ namespace NotificationChannels\Pr0gramm; use Illuminate\Http\Client\RequestException; -use NotificationChannels\Pr0gramm\Exceptions\CouldNotSendNotification; use Illuminate\Notifications\Notification; +use NotificationChannels\Pr0gramm\Exceptions\CouldNotSendNotification; use NotificationChannels\Pr0gramm\Exceptions\Pr0grammRateLimitReached; use Tschucki\Pr0grammApi\Facades\Pr0grammApi; @@ -22,9 +22,9 @@ public function __construct() * Send the given notification. * * @param mixed $notifiable - * @param \Illuminate\Notifications\Notification $notification + * @param Notification $notification * - * @throws \NotificationChannels\Pr0gramm\Exceptions\CouldNotSendNotification + * @throws CouldNotSendNotification * @throws RequestException * @throws Pr0grammRateLimitReached */ @@ -52,6 +52,5 @@ public function send(mixed $notifiable, Notification $notification): void if ($response->status() === 429) { throw Pr0grammRateLimitReached::rateLimitReached(); } - } } diff --git a/src/Pr0grammServiceProvider.php b/src/Pr0grammServiceProvider.php index 20a8732a..48b0cbca 100644 --- a/src/Pr0grammServiceProvider.php +++ b/src/Pr0grammServiceProvider.php @@ -16,13 +16,12 @@ public function boot() ->give(function () { return Pr0grammApi::class; }); - } public function register(): void { Notification::resolved(static function (ChannelManager $service) { - $service->extend('pr0gramm', static fn ($app) => $app->make(Pr0grammChannel::class)); + $service->extend('pr0gramm', static fn($app) => $app->make(Pr0grammChannel::class)); }); } } From d89cf55610d978169d482dfe8d47c53984f38502 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 13 Jan 2024 23:10:11 +0000 Subject: [PATCH 7/7] Apply fixes from StyleCI --- src/Exceptions/CouldNotSendNotification.php | 10 +++++----- src/Exceptions/Pr0grammRateLimitReached.php | 2 +- src/Pr0grammChannel.php | 12 ++++++------ src/Pr0grammServiceProvider.php | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php index 2b04c2d6..51fb56fb 100644 --- a/src/Exceptions/CouldNotSendNotification.php +++ b/src/Exceptions/CouldNotSendNotification.php @@ -8,26 +8,26 @@ class CouldNotSendNotification extends Exception { public static function serviceRespondedWithAnError($body): static { - return new static("Descriptive error message. " . $body); + return new static('Descriptive error message. '.$body); } public static function couldNotFindToPr0grammMethod(): static { - return new static("Could not find toPr0gramm method on the notification."); + return new static('Could not find toPr0gramm method on the notification.'); } public static function couldNotFindGetPr0grammNameMethod(): static { - return new static("Could not find getPr0grammName method on the notifiable object."); + return new static('Could not find getPr0grammName method on the notifiable object.'); } public static function noStringForMessageProvided(): static { - return new static("No string for message provided. Please provide a string in the toPr0gramm Method."); + return new static('No string for message provided. Please provide a string in the toPr0gramm Method.'); } public static function rateLimitReached(): static { - return new static("Rate limit reached. Please wait a few seconds before sending another message."); + return new static('Rate limit reached. Please wait a few seconds before sending another message.'); } } diff --git a/src/Exceptions/Pr0grammRateLimitReached.php b/src/Exceptions/Pr0grammRateLimitReached.php index 228fd75d..c0055ed6 100644 --- a/src/Exceptions/Pr0grammRateLimitReached.php +++ b/src/Exceptions/Pr0grammRateLimitReached.php @@ -8,6 +8,6 @@ class Pr0grammRateLimitReached extends Exception { public static function rateLimitReached(): static { - return new static("Rate limit reached. Please wait a few seconds before sending another message."); + return new static('Rate limit reached. Please wait a few seconds before sending another message.'); } } diff --git a/src/Pr0grammChannel.php b/src/Pr0grammChannel.php index a53e20b0..adae5642 100644 --- a/src/Pr0grammChannel.php +++ b/src/Pr0grammChannel.php @@ -13,7 +13,7 @@ class Pr0grammChannel public function __construct() { $loggedIn = Pr0grammApi::loggedIn(); - if (!$loggedIn['loggedIn']) { + if (! $loggedIn['loggedIn']) { Pr0grammApi::login(config('services.pr0gramm.username'), config('services.pr0gramm.password')); } } @@ -21,8 +21,8 @@ public function __construct() /** * Send the given notification. * - * @param mixed $notifiable - * @param Notification $notification + * @param mixed $notifiable + * @param Notification $notification * * @throws CouldNotSendNotification * @throws RequestException @@ -30,16 +30,16 @@ public function __construct() */ public function send(mixed $notifiable, Notification $notification): void { - if (!method_exists($notification, 'toPr0gramm')) { + if (! method_exists($notification, 'toPr0gramm')) { throw CouldNotSendNotification::couldNotFindToPr0grammMethod(); } - if (!method_exists($notifiable, 'getPr0grammName')) { + if (! method_exists($notifiable, 'getPr0grammName')) { throw CouldNotSendNotification::couldNotFindGetPr0grammNameMethod(); } $message = $notification->toPr0gramm($notifiable); - if (!is_string($message)) { + if (! is_string($message)) { throw CouldNotSendNotification::noStringForMessageProvided(); } diff --git a/src/Pr0grammServiceProvider.php b/src/Pr0grammServiceProvider.php index 48b0cbca..f5504912 100644 --- a/src/Pr0grammServiceProvider.php +++ b/src/Pr0grammServiceProvider.php @@ -21,7 +21,7 @@ public function boot() public function register(): void { Notification::resolved(static function (ChannelManager $service) { - $service->extend('pr0gramm', static fn($app) => $app->make(Pr0grammChannel::class)); + $service->extend('pr0gramm', static fn ($app) => $app->make(Pr0grammChannel::class)); }); } }