Skip to content

Commit

Permalink
Merge pull request #15 from laravel-notification-channels/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mbardelmeijer authored Jul 5, 2022
2 parents dc65de8 + 7bdce82 commit 12d3da0
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 164 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check & fix styling

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
19 changes: 7 additions & 12 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.4]
laravel: [8.*, 5.8.*, 6.*, 7.*]
os: [ubuntu-latest]
php: [8.1]
laravel: [9.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*
- laravel: 5.8.*
testbench: 3.8.*
- laravel: 9.*
testbench: 7.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

Expand All @@ -38,12 +32,13 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
composer.phar
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
47 changes: 47 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
;

return (new Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to `CMSMS` will be documented in this file

## [3.0.0] - 2020-09-09
#### Changed
- General cleanup of package. Added return types.
- Added support for Laravel 9.0
- Added support for PHP 8.1
- Dropped support for Laravel 8 and below.
- Dropped support for PHP 8.0 and below.

## [2.2.0] - 2020-09-09
#### Changed
- Added support for Laravel 8.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CMSMS notifications channel for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/cmsms.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/cmsms)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/laravel-notification-channels/cmsms/run-tests?label=tests)
[![run-tests](https://github.com/laravel-notification-channels/cmsms/actions/workflows/run-tests.yml/badge.svg)](https://github.com/laravel-notification-channels/cmsms/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/cmsms.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/cmsms)

This package makes it easy to send [CMSMS messages](https://docs.cmtelecom.com/en/api/business-messaging-api/1.0/index) with Laravel.
Expand Down
19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
}
],
"require": {
"php": "^7.2",
"php": "^8.1",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.2|^7.0",
"illuminate/notifications": "~5.8 || ~6.0 || ^7.0 || ^8.0",
"illuminate/support": "~5.8 || ~6.0 || ^7.0 || ^8.0",
"orchestra/testbench": "~3.8.0 || ^4.0 || ^5.0 || ^6.0"
"guzzlehttp/guzzle": "^7.1",
"illuminate/notifications": "^9.0",
"illuminate/support": "^9.0"
},
"require-dev": {
"mockery/mockery": "~1.3.1",
"phpunit/phpunit": "~8.0"
"friendsofphp/php-cs-fixer": "^3.6",
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.5"
},
"config": {
"sort-packages": true
Expand All @@ -46,6 +47,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test": "vendor/bin/phpunit"
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
}
}
31 changes: 11 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="CmsmsChannel Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="CmsmsChannel Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
24 changes: 5 additions & 19 deletions src/CmsmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,14 @@

class CmsmsChannel
{
/** @var CmsmsClient */
protected $client;

/**
* @param CmsmsClient $client
*/
public function __construct(CmsmsClient $client)
{
$this->client = $client;
public function __construct(
protected CmsmsClient $client,
) {
}

/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
*
* @throws \NotificationChannels\Cmsms\Exceptions\CouldNotSendNotification
*/
public function send($notifiable, Notification $notification)
public function send($notifiable, Notification $notification): void
{
if (!$recipient = $notifiable->routeNotificationFor('Cmsms')) {
if (! $recipient = $notifiable->routeNotificationFor('Cmsms')) {
return;
}

Expand Down
38 changes: 8 additions & 30 deletions src/CmsmsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,22 @@

class CmsmsClient
{
const GATEWAY_URL = 'https://sgw01.cm.nl/gateway.ashx';
public const GATEWAY_URL = 'https://sgw01.cm.nl/gateway.ashx';

/** @var GuzzleClient */
protected $client;

/** @var string */
protected $productToken;

/**
* @param GuzzleClient $client
* @param string $productToken
*/
public function __construct(GuzzleClient $client, string $productToken)
{
$this->client = $client;
$this->productToken = $productToken;
public function __construct(
protected GuzzleClient $client,
protected string $productToken,
) {
}

/**
* @param CmsmsMessage $message
* @param string $recipient
*
* @throws CouldNotSendNotification
*/
public function send(CmsmsMessage $message, string $recipient)
public function send(CmsmsMessage $message, string $recipient): void
{
if (is_null(Arr::get($message->toXmlArray(), 'FROM'))) {
$message->originator(config('services.cmsms.originator'));
}

$response = $this->client->request('POST', static::GATEWAY_URL, [
'body' => $this->buildMessageXml($message, $recipient),
'body' => $this->buildMessageXml($message, $recipient),
'headers' => [
'Content-Type' => 'application/xml',
],
Expand All @@ -51,17 +35,11 @@ public function send(CmsmsMessage $message, string $recipient)
// API returns an empty string on success
// On failure, only the error string is passed
$body = $response->getBody()->getContents();
if (!empty($body)) {
if (! empty($body)) {
throw CouldNotSendNotification::serviceRespondedWithAnError($body);
}
}

/**
* @param CmsmsMessage $message
* @param string $recipient
*
* @return string
*/
public function buildMessageXml(CmsmsMessage $message, string $recipient): string
{
$xml = new SimpleXMLElement('<MESSAGES/>');
Expand Down
Loading

0 comments on commit 12d3da0

Please sign in to comment.