Skip to content

Commit

Permalink
Merge pull request #1 from Muetze42/development
Browse files Browse the repository at this point in the history
refactor: nullable columns and use laravel 11 casts
  • Loading branch information
Muetze42 authored May 21, 2024
2 parents d88fd83 + 9ca6b82 commit ed0f814
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 4,014 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.vscode
/vendor
.phpunit.result.cache
/composer.lock
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
},
"require": {
"php": "^8.0",
"illuminate/events": "^8.0|^9.0|^10.0|^11.0",
"illuminate/mail": "^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
"illuminate/events": "^11.0",
"illuminate/mail": "^11.0",
"illuminate/support": "^11.0"
},
"authors": [
{
Expand All @@ -29,5 +29,8 @@
"psr-4": {
"NormanHuth\\LaravelEmailLog\\": "src/"
}
},
"require-dev": {
"laravel/pint": "^1.15"
}
}
20 changes: 10 additions & 10 deletions database/migrations/2023_10_18_000000_create_email_logs_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
return new class() extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,15 +13,15 @@ public function up(): void
{
Schema::create('email_logs', function (Blueprint $table) {
$table->id();
$table->string('subject');
$table->text('body');
$table->json('from');
$table->json('to');
$table->json('bbc');
$table->json('cc');
$table->json('reply_to');
$table->json('headers');
$table->json('attachments');
$table->string('subject')->nullable();
$table->text('body')->nullable();
$table->json('from')->nullable();
$table->json('to')->nullable();
$table->json('bbc')->nullable();
$table->json('cc')->nullable();
$table->json('reply_to')->nullable();
$table->json('headers')->nullable();
$table->json('attachments')->nullable();
$table->boolean('is_html');
$table->tinyInteger('priority', false, true);
$table->nullableMorphs('authenticatable');
Expand Down
186 changes: 186 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"preset": "psr12",
"notName": [
"_ide_help*.php",
".phpstorm.meta.php",
"*.blade.php"
],
"rules": {
"array_syntax": {
"syntax": "short"
},
"binary_operator_spaces": {
"default": "single_space"
},
"blank_line_before_statement": {
"statements": [
"continue",
"return"
]
},
"braces_position": {
"control_structures_opening_brace": "same_line",
"functions_opening_brace": "next_line_unless_newline_at_signature_end",
"anonymous_functions_opening_brace": "same_line",
"classes_opening_brace": "next_line_unless_newline_at_signature_end",
"anonymous_classes_opening_brace": "next_line_unless_newline_at_signature_end",
"allow_single_line_empty_anonymous_classes": false,
"allow_single_line_anonymous_functions": false
},
"class_attributes_separation": {
"elements": {
"const": "one",
"method": "one",
"property": "one",
"trait_import": "none"
}
},
"class_definition": {
"multi_line_extends_each_single_line": true,
"single_item_single_line": true,
"single_line": true
},
"concat_space": {
"spacing": "none"
},
"constant_case": {
"case": "lower"
},
"control_structure_continuation_position": {
"position": "same_line"
},
"fully_qualified_strict_types": false,
"increment_style": {
"style": "post"
},
"method_argument_space": {
"on_multiline": "ignore"
},
"multiline_whitespace_before_semicolons": {
"strategy": "no_multi_line"
},
"no_extra_blank_lines": {
"tokens": [
"extra",
"throw",
"use"
]
},
"no_mixed_echo_print": {
"use": "echo"
},
"no_spaces_around_offset": {
"positions": [
"inside",
"outside"
]
},
"no_superfluous_phpdoc_tags": {
"allow_mixed": true,
"allow_unused_params": true
},
"no_unneeded_control_parentheses": {
"statements": [
"break",
"clone",
"continue",
"echo_print",
"return",
"switch_case",
"yield"
]
},
"ordered_imports": {
"sort_algorithm": "alpha",
"imports_order": [
"const",
"class",
"function"
]
},
"phpdoc_align": {
"align": "left",
"spacing": {
"param": 2
}
},
"phpdoc_order": {
"order": [
"param",
"return",
"throws"
]
},
"phpdoc_separation": {
"groups": [
[
"deprecated",
"link",
"see",
"since"
],
[
"author",
"copyright",
"license"
],
[
"category",
"package",
"subpackage"
],
[
"property",
"property-read",
"property-write"
],
[
"param",
"return"
]
]
},
"phpdoc_summary": false,
"phpdoc_tag_type": {
"tags": {
"inheritdoc": "inline"
}
},
"phpdoc_to_comment": false,
"psr_autoloading": false,
"return_type_declaration": {
"space_before": "none"
},
"self_accessor": false,
"simplified_null_return": false,
"single_class_element_per_statement": {
"elements": [
"const",
"property"
]
},
"single_line_comment_style": {
"comment_types": [
"hash"
]
},
"trailing_comma_in_multiline": {
"elements": [
"arrays"
]
},
"visibility_required": {
"elements": [
"method",
"property"
]
},
"yoda_style": {
"always_move_variable": false,
"equal": false,
"identical": false,
"less_and_greater": false
}
},
"Laravel/laravel_phpdoc_alignment": true
}
11 changes: 4 additions & 7 deletions src/Listeners/LogSentMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Events\MessageSent;
use NormanHuth\LaravelEmailLog\Models\EmailLog;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Part\DataPart;

Expand Down Expand Up @@ -45,27 +44,25 @@ public function handle(MessageSent $event): void
}

/**
* @param \Symfony\Component\Mime\Address[]|null $addresses
* @param \Symfony\Component\Mime\Address[]|null $addresses
*
* @return array
*/
protected function parseAddresses(?array $addresses): array
{
return array_map(
fn(Address $address) => $address->toString(),
fn (Address $address) => $address->toString(),
(array) $addresses
);
}

/**
* @param \Symfony\Component\Mime\Part\DataPart[]|null $attachments
* @param \Symfony\Component\Mime\Part\DataPart[]|null $attachments
*
* @return array
*/
protected function parseAttachments(?array $attachments): array
{
return array_map(
fn(DataPart $attachment) => $attachment->asDebugString(),
fn (DataPart $attachment) => $attachment->asDebugString(),
(array) $attachments
);
}
Expand Down
28 changes: 14 additions & 14 deletions src/Models/EmailLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EmailLog extends Model
*
* @var array<int, string>
*/
protected $fillable = [
protected array $fillable = [
'subject',
'body',
'from',
Expand All @@ -27,21 +27,21 @@ class EmailLog extends Model
];

/**
* The attributes that should be cast.
* Get the attributes that should be cast.
*
* @var array<string, string>
* @return array<string, string>
*/
protected $casts = [
'from' => 'array',
'to' => 'array',
'bbc' => 'array',
'cc' => 'array',
'reply_to' => 'array',
'headers' => 'array',
'attachments' => 'array',
'is_html' => 'bool',
'priority' => 'int',
];
protected function casts(): array
{
return [
'is_pre_order' => 'bool',
'is_posa' => 'bool',
'is_ptr_allowed' => 'bool',
'is_returnable' => 'bool',
'purchase_price' => 'decimal:2',
'supplier_price' => 'decimal:2',
];
}

/**
* Get the parent authenticatable model.
Expand Down
10 changes: 5 additions & 5 deletions src/Providers/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace NormanHuth\LaravelEmailLog\Providers;

use Illuminate\Mail\Events\MessageSent;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use NormanHuth\LaravelEmailLog\Listeners\LogSentMessage;

class PackageServiceProvider extends ServiceProvider
Expand All @@ -14,7 +14,7 @@ class PackageServiceProvider extends ServiceProvider
*/
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../../config/email-log.php', 'email-log');
$this->mergeConfigFrom(__DIR__.'/../../config/email-log.php', 'email-log');
}

/**
Expand All @@ -24,14 +24,14 @@ public function boot(): void
{
Event::listen(MessageSent::class, LogSentMessage::class);

$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
$this->loadMigrationsFrom(__DIR__.'/../../database/migrations');

$this->publishes([
__DIR__ . '/../../config/email-log.php' => config_path('email-log.php'),
__DIR__.'/../../config/email-log.php' => config_path('email-log.php'),
], 'email-log-config');

$this->publishes([
__DIR__ . '/../../database/migrations' => database_path('migrations')
__DIR__.'/../../database/migrations' => database_path('migrations'),
], 'email-log-migrations');
}
}
6 changes: 1 addition & 5 deletions src/Traits/LaravelNovaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ trait LaravelNovaTrait
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
*
* @return array
* @throws \Laravel\Nova\Exceptions\HelperNotSupported
*/
public function logFields(NovaRequest $request): array
Expand Down Expand Up @@ -120,16 +118,14 @@ protected function formatArrayForDetail(?array $data): string
}

/**
* @param array|null $data
*
* @return string
*/
protected function formatArrayForIndex(?array $data): string
{
$data = (array) $data;

$return = $data[0] ?? '';

return count($data) > 1 ? $return . ' ...' : $return;
return count($data) > 1 ? $return.' ...' : $return;
}
}
Loading

0 comments on commit ed0f814

Please sign in to comment.