Skip to content

Commit

Permalink
fix: restrict to laravel 9 (#2559)
Browse files Browse the repository at this point in the history
* fix: restrict to laravel 9

* fix: upgrade

* fix: wip

* fix: wip

* fix: wip

* fix: wip

* fix: phpstan

* fix: wip

* fix: wip

* fix: wip

* fix: wip
  • Loading branch information
binaryk authored Feb 10, 2022
1 parent 9153d09 commit 7934ab2
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 94 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PHPStan

on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v1

- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
33 changes: 0 additions & 33 deletions .github/workflows/psalm.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.0]
laravel: [^8.0, ^9.0]
php: [8.0, 8.1]
laravel: [^9.0]
stability: [prefer-stable]
include:
- laravel: 8.*
testbench: ^6.6
- laravel: ^9.0
testbench: ^7.0

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

Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
5 changes: 5 additions & 0 deletions Upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### From v3 to v4

Upgrading from v3 to v4 is straightforward. The biggest change is that we dropped support for Laravel bellow than 9, and are using PHP 8 features.


20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.0|^9.0",
"illuminate/support": "^9.0",
"opis/closure": "^3.6"
},
"require-dev": {
"brianium/paratest": "^6.2",
"nunomaduro/collision": "^5.3",
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.3",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^7.0",
"phpstan/extension-installer": "^1.1",
"phpunit/phpunit": "^9.5",
"spatie/laravel-ray": "^1.9",
"spatie/test-time": "^1.2",
"vimeo/psalm": "^4.4"
"spatie/test-time": "^1.2"
},
"autoload": {
"psr-4": {
Expand All @@ -41,12 +42,15 @@
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"analyse": "vendor/bin/phpstan analyse",
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
Expand Down
18 changes: 18 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
parameters:
ignoreErrors:
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Models/MailatorSchedule.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Replacers/ModelAttributesReplacer.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Exceptions/InvalidTemplateException.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Exceptions/InstanceException.php
12 changes: 12 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
includes:
- phpstan-baseline.neon

parameters:
level: 2
paths:
- src
- config
- database
tmpDir: build/phpstan
checkModelProperties: true
checkMissingIterableValueType: false
16 changes: 0 additions & 16 deletions psalm.xml.dist

This file was deleted.

18 changes: 9 additions & 9 deletions src/Constraints/AfterConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool
}

if ($schedule->toDays() > 0) {
if (now()->lt($schedule->timestampTarget()->addDays($schedule->toDays()))) {
if (now()->floorSeconds()->lt($schedule->timestampTarget()->addDays($schedule->toDays()))) {
return false;
}

return $schedule->isOnce()
? $schedule->timestamp_target->diffInDays(now()) === $schedule->toDays()
: $schedule->timestamp_target->diffInDays(now()) > $schedule->toDays();
? $schedule->timestamp_target->diffInDays(now()->floorSeconds()) === $schedule->toDays()
: $schedule->timestamp_target->diffInDays(now()->floorSeconds()) > $schedule->toDays();
}

if ($schedule->toHours() > 0) {
if (now()->lt($schedule->timestampTarget()->addHours($schedule->toHours()))) {
if (now()->floorSeconds()->lt($schedule->timestampTarget()->addHours($schedule->toHours()))) {
return false;
}

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInHours(now()) === $schedule->toHours()
: $schedule->timestamp_target->diffInHours(now()) > $schedule->toHours();
? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->toHours()
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->toHours();
}

if (now()->lt($schedule->timestampTarget()->addMinutes($schedule->delay_minutes))) {
if (now()->floorSeconds()->lt($schedule->timestampTarget()->addMinutes($schedule->delay_minutes))) {
return false;
}

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInHours(now()) === $schedule->delay_minutes
: $schedule->timestamp_target->diffInHours(now()) > $schedule->delay_minutes;
? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->delay_minutes
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->delay_minutes;
}
}
6 changes: 3 additions & 3 deletions src/Constraints/BeforeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool
}

// if already expired
if ($schedule->timestamp_target->lte(now())) {
if ($schedule->timestamp_target->lte(now()->floorSeconds())) {
return false;
}

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInDays(now()) === $schedule->toDays()
: $schedule->timestamp_target->diffInDays(now()) < $schedule->toDays();
? $schedule->timestamp_target->diffInDays(now()->floorSeconds()) === $schedule->toDays()
: $schedule->timestamp_target->diffInDays(now()->floorSeconds()) < $schedule->toDays();
}
}
3 changes: 3 additions & 0 deletions src/Models/Builders/MailatorSchedulerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Database\Eloquent\Builder;

/**
* @mixin \Illuminate\Database\Query\Builder
*/
class MailatorSchedulerBuilder extends Builder
{
public function ready(): self
Expand Down
1 change: 1 addition & 0 deletions src/Models/Concerns/ConstraintsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function constraintsNotSatisfiedDescriptions(): array
return collect($this->constraints)
->map(fn (string $event) => unserialize($event))
->filter(fn ($event) => is_subclass_of($event, Descriptionable::class))
->filter(fn ($event) => is_subclass_of($event, SendScheduleConstraint::class))
->filter(fn ($event) => ! $event->canSend($this, $this->logs))
->reduce(function ($base, Descriptionable $descriable) {
return array_merge($base, $descriable::conditions());
Expand Down
5 changes: 4 additions & 1 deletion src/Models/Concerns/WithUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

/**
* @property string $uuid
*/
trait WithUuid
{
public static function bootWithUuid()
{
static::creating(function (Model $model) {
static::creating(function ($model) {
if (! $model->uuid) {
$model->setAttribute('uuid', Str::uuid());
}
Expand Down
24 changes: 14 additions & 10 deletions src/Models/MailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@

use Binarcode\LaravelMailator\Models\Concerns\WithUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Mail\Mailable;
use Illuminate\Support\Collection;
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;

/**
* Class MailTemplate
* @property string name
* @property string subject
* @property string from_email
* @property string from_name
* @property string html
* @property string email_html
* @property string webview_html
* @property string mailable_class
* @property string webvimailable_classew_html
* @property string $uuid
* @property string $name
* @property string $subject
* @property string $from_email
* @property string $from_name
* @property string $html
* @property string $email_html
* @property string $webview_html
* @property string $mailable_class
* @property string $webvimailable_classew_html
* @property-read Collection $placeholders
* @package App\Models
*/
class MailTemplate extends Model implements MailTemplateable
{
use WithUuid;

protected $fillable = [
'uuid',
'name',
'from_email',
'from_name',
Expand All @@ -36,7 +40,7 @@ class MailTemplate extends Model implements MailTemplateable
'mailable_class',
];

public function placeholders()
public function placeholders(): HasMany
{
return $this->hasMany(
config('mailator.templates.placeholder_model') ?? MailTemplatePlaceholder::class,
Expand Down
10 changes: 6 additions & 4 deletions src/Models/MailTemplatePlaceholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

/**
* Class MailTemplate
* @property string name
* @property string description
* @property int mail_template_id
* @property-read MailTemplate mailTemplate
*
* @property string $name
* @property string $description
* @property int $mail_template_id
* @property-read MailTemplate $mailTemplate
*
* @package App\Models
*/
class MailTemplatePlaceholder extends Model
Expand Down
7 changes: 6 additions & 1 deletion src/Models/MailatorLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
namespace Binarcode\LaravelMailator\Models;

use Carbon\Carbon;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Model;

/**
* Class MailatorLog
* @property string $name
* @property string $status
* @property Carbon $created_at
* @property array recipients
* @property Arrayable|array $recipients
* @property Carbon $action_at
* @property Carbon $updated_at
* @property Carbon $exception
* @package Binarcode\LaravelMailator\Models
*/
class MailatorLog extends Model
Expand Down
Loading

0 comments on commit 7934ab2

Please sign in to comment.