Skip to content

Commit 0f0e4a8

Browse files
authored
Merge pull request #2551 from BinarCode/2.x
2.x
2 parents d2d048c + 32fdb16 commit 0f0e4a8

File tree

19 files changed

+248
-82
lines changed

19 files changed

+248
-82
lines changed

.github/workflows/php-cs-fixer.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,21 @@ name: Check & fix styling
33
on: [push]
44

55
jobs:
6-
style:
6+
php-cs-fixer:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- name: Checkout code
11-
uses: actions/checkout@v1
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.head_ref }}
1214

13-
- name: Fix style
14-
uses: docker://oskarstark/php-cs-fixer-ga
15-
with:
16-
args: --config=.php_cs --allow-risky=yes
15+
- name: Run PHP CS Fixer
16+
uses: docker://oskarstark/php-cs-fixer-ga
17+
with:
18+
args: --config=.php_cs.dist.php --allow-risky=yes
1719

18-
- name: Extract branch name
19-
shell: bash
20-
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
21-
id: extract_branch
22-
23-
- name: Commit changes
24-
uses: stefanzweifel/[email protected]
25-
with:
26-
commit_message: Fix styling
27-
branch: ${{ steps.extract_branch.outputs.branch }}
28-
env:
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
- name: Commit changes
21+
uses: stefanzweifel/git-auto-commit-action@v4
22+
with:
23+
commit_message: Fix styling

.github/workflows/psalm.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Psalm
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- 'psalm.xml.dist'
8+
9+
jobs:
10+
psalm:
11+
name: psalm
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '8.0'
20+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
21+
coverage: none
22+
23+
- name: Cache composer dependencies
24+
uses: actions/cache@v2
25+
with:
26+
path: vendor
27+
key: composer-${{ hashFiles('composer.lock') }}
28+
29+
- name: Run composer install
30+
run: composer install -n --prefer-dist
31+
32+
- name: Run psalm
33+
run: ./vendor/bin/psalm --output-format=github

.github/workflows/run-tests.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [8.0, 7.4]
13-
laravel: [^8.0, ^7.0]
12+
php: [8.0]
13+
laravel: [^8.0]
1414
dependency-version: [prefer-stable]
1515
include:
1616
- laravel: ^8.0
1717
testbench: ^6.0
18-
- laravel: ^7.0
19-
testbench: ^5.2
2018

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

.gitignore

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
build
2-
composer.lock
3-
vendor
4-
coverage
51
.idea
6-
output
7-
docs/node_modules
8-
docs/.vuepress/dist
2+
.php_cs
93
.php_cs.cache
104
.phpunit.result.cache
5+
build
6+
composer.lock
7+
coverage
8+
docs
9+
phpunit.xml
10+
psalm.xml
11+
testbench.yaml
12+
vendor
13+
node_modules
14+
.php-cs-fixer.cache
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
22

33
$finder = Symfony\Component\Finder\Finder::create()
4-
->notPath('bootstrap/*')
5-
->notPath('storage/*')
6-
->notPath('storage/*')
7-
->notPath('resources/view/mail/*')
84
->in([
95
__DIR__ . '/src',
106
__DIR__ . '/tests',
@@ -14,14 +10,14 @@
1410
->ignoreDotFiles(true)
1511
->ignoreVCS(true);
1612

17-
return PhpCsFixer\Config::create()
13+
return (new PhpCsFixer\Config())
1814
->setRules([
1915
'@PSR2' => true,
2016
'array_syntax' => ['syntax' => 'short'],
21-
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
17+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
2218
'no_unused_imports' => true,
2319
'not_operator_with_successor_space' => true,
24-
'trailing_comma_in_multiline_array' => true,
20+
'trailing_comma_in_multiline' => true,
2521
'phpdoc_scalar' => true,
2622
'unary_operator_spaces' => true,
2723
'binary_operator_spaces' => true,
@@ -30,9 +26,15 @@
3026
],
3127
'phpdoc_single_line_var_spacing' => true,
3228
'phpdoc_var_without_name' => true,
29+
'class_attributes_separation' => [
30+
'elements' => [
31+
'method' => 'one',
32+
],
33+
],
3334
'method_argument_space' => [
3435
'on_multiline' => 'ensure_fully_multiline',
3536
'keep_multiple_spaces_after_comma' => true,
36-
]
37+
],
38+
'single_trait_insert_per_statement' => true,
3739
])
3840
->setFinder($finder);

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ $scheduler = MailatorSchedule::init('Invoice reminder.')
154154

155155
The `CustomAction` should implement the `Binarcode\LaravelMailator\Actions\Action` class.
156156

157+
### Target
158+
159+
You can link the scheduler with any entity like this:
160+
161+
```php
162+
MailatorSchedule::init('Invoice reminder.')
163+
->mailable(new InvoiceReminderMailable())
164+
->days(1)
165+
->target($invoice)
166+
->save();
167+
```
168+
169+
and then in the `Invoice` model you can get all emails related to it:
170+
171+
```php
172+
// app/Models/Invoice.php
173+
public function schedulers()
174+
{
175+
return $this->morphMany(Binarcode\LaravelMailator\Models\MailatorSchedule::class, 'targetable');
176+
}
177+
...
178+
```
179+
157180
### Testing
158181

159182
``` bash

composer.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^7.4|^8.0",
21-
"illuminate/support": "^7.0|^8.0",
22-
"opis/closure": "^3.5",
23-
"tijsverkoyen/css-to-inline-styles": "^2.2"
20+
"php": "^8.0",
21+
"illuminate/contracts": "^8.37",
22+
"opis/closure": "^3.6"
2423
},
2524
"require-dev": {
26-
"friendsofphp/php-cs-fixer": "^2.16",
27-
"laravel/legacy-factories": "^1.0",
28-
"orchestra/testbench": "^5.2|^6.0",
29-
"phpunit/phpunit": "^9.0",
30-
"spatie/test-time": "^1.2"
25+
"brianium/paratest": "^6.2",
26+
"nunomaduro/collision": "^5.3",
27+
"orchestra/testbench": "^6.15",
28+
"phpunit/phpunit": "^9.3",
29+
"spatie/laravel-ray": "^1.9",
30+
"spatie/test-time": "^1.2",
31+
"vimeo/psalm": "^4.4"
3132
},
3233
"autoload": {
3334
"psr-4": {
@@ -40,9 +41,9 @@
4041
}
4142
},
4243
"scripts": {
43-
"test": "vendor/bin/phpunit",
44-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
45-
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
44+
"psalm": "vendor/bin/psalm",
45+
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
46+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
4647
},
4748
"config": {
4849
"sort-packages": true

database/migrations/create_mailator_tables.php.stub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CreateMailatorTables extends Migration
1515

1616
$table->string('name', 100)->nullable();
1717
$table->text('mailable_class')->nullable();
18+
$table->nullableMorphs('targetable');
1819
$table->text('action')->nullable();
1920
$table->unsignedInteger('delay_minutes')->nullable()->comment('Number of hours/days.');
2021
$table->enum('time_frame_origin', [
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="4"
3+
errorLevel="6"
44
findUnusedVariablesAndParams="true"
55
resolveFromConfigFile="true"
6-
useDocblockPropertyTypes="true"
76
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
87
xmlns="https://getpsalm.org/schema/config"
98
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
109
>
1110
<projectFiles>
1211
<directory name="src"/>
12+
<ignoreFiles>
13+
<directory name="vendor"/>
14+
</ignoreFiles>
1315
</projectFiles>
14-
15-
<issueHandlers>
16-
</issueHandlers>
17-
18-
<plugins>
19-
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
20-
</plugins>
2116
</psalm>

src/Jobs/SendMailJob.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
class SendMailJob implements ShouldQueue
1515
{
16-
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
16+
use Dispatchable;
17+
use InteractsWithQueue;
18+
use Queueable;
19+
use SerializesModels;
1720

1821
public bool $deleteWhenMissingModels = true;
1922

0 commit comments

Comments
 (0)