chore: format and refactor the Connected Service component to use dto collection

This commit is contained in:
= 2026-05-11 07:42:09 +00:00
parent ca628fb009
commit 9443ac181c
35 changed files with 141 additions and 236 deletions

View File

@ -4,8 +4,7 @@
namespace App\Actions\Fortify;
use App\Concerns\PasswordValidationRules;
use App\Concerns\ProfileValidationRules;
use App\Concerns\{PasswordValidationRules, ProfileValidationRules};
use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Data\Ui\ConnectedServices;
use Illuminate\Support\Collection;
/**
* A collection of connected services.
*
* @extends Collection<int, ConnectedServiceData>
*/
final class ConnectedServiceCollectionData extends Collection {}

View File

@ -4,16 +4,11 @@
namespace App\Data\Ui\ConnectedServices;
use App\Enums\ConnectionStatus;
use App\Enums\ConnectionTechTypes;
use Livewire\Wireable;
use Spatie\LaravelData\Concerns\WireableData;
use App\Enums\{ConnectionStatus, ConnectionTechTypes};
use Spatie\LaravelData\Data;
final class ConnectedServiceData extends Data implements Wireable
final class ConnectedServiceData extends Data
{
use WireableData;
public function __construct(
public string $name,
public string $icon,

View File

@ -1,18 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Data\Ui\ConnectedServices;
use Livewire\Wireable;
use Spatie\LaravelData\Concerns\WireableData;
use Spatie\LaravelData\Data;
final class ConnectedServicesData extends Data implements Wireable
{
use WireableData;
public function __construct(
public ConnectedServiceCollectionData $services,
) {}
}

View File

@ -7,8 +7,7 @@
use App\Data\Users\UserData;
use App\Enums\RolesStatus;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
use Spatie\LaravelData\{Data, DataCollection};
final class RoleData extends Data
{

View File

@ -4,8 +4,7 @@
namespace App\Livewire\Actions;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\{Auth, Session};
final class Logout
{

View File

@ -8,8 +8,7 @@
use Flux\Flux;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Title;
use Livewire\Attributes\{Computed, Title};
use Livewire\Component;
#[Title('Profile settings')]

View File

@ -9,15 +9,9 @@
use Flux\Flux;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication;
use Laravel\Fortify\Actions\DisableTwoFactorAuthentication;
use Laravel\Fortify\Actions\EnableTwoFactorAuthentication;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Title;
use Livewire\Attributes\Validate;
use Laravel\Fortify\Actions\{ConfirmTwoFactorAuthentication, DisableTwoFactorAuthentication, EnableTwoFactorAuthentication};
use Laravel\Fortify\{Features, Fortify};
use Livewire\Attributes\{Computed, Locked, Title, Validate};
use Livewire\Component;
#[Title('Security settings')]

View File

@ -6,8 +6,7 @@
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Attributes\{Fillable, Hidden};
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -20,6 +19,7 @@ final class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory;
use Notifiable;
use TwoFactorAuthenticatable;

View File

@ -5,8 +5,7 @@
namespace App\Providers;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\{DB, Date};
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rules\Password;

View File

@ -4,13 +4,11 @@
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\{CreateNewUser, ResetUserPassword};
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\{ServiceProvider, Str};
use Laravel\Fortify\Fortify;
final class FortifyServiceProvider extends ServiceProvider

View File

@ -4,9 +4,8 @@
namespace App\Providers;
use Illuminate\Support\Arr;
use Illuminate\Support\{Arr, ServiceProvider};
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
final class ScopeServiceProvider extends ServiceProvider
{
@ -26,10 +25,10 @@ public function registerScopeDirective(): void
*
* https://github.com/konradkalemba/blade-components-scoped-slots
*/
Blade::directive("scope", function ($expression) {
Blade::directive('scope', function ($expression) {
// Split the expression by `top-level` commas (not in parentheses)
$directiveArguments = preg_split("/,(?![^\(\(]*[\)\)])/", $expression);
$directiveArguments = array_map("trim", $directiveArguments);
$directiveArguments = array_map('trim', $directiveArguments);
// PHP 8.5 Safe Unpacking (Prevents "Undefined array key" crashes)
$name = $directiveArguments[0] ?? "''";
@ -40,7 +39,7 @@ public function registerScopeDirective(): void
$uses = array_flip($uses);
$uses[] = '$__env';
$uses[] = '$__bladeCompiler';
$uses = implode(",", $uses);
$uses = implode(',', $uses);
/**
* Slot names can`t contains dot , eg: `user.city`.
@ -48,12 +47,12 @@ public function registerScopeDirective(): void
*
* Later, on component it will be replaced back.
*/
$name = str_replace(".", "___", $name);
$name = str_replace('.', '___', $name);
// PHP 8.5 Safe Loop Check
return "<?php \$__bladeCompiler = \$__bladeCompiler ?? null; \$__env->slot({$name}, function({$functionArguments}) use ({$uses}) { \$loop = !empty(\$__env->getLoopStack()) ? (object) \$__env->getLoopStack()[0] : null; ?>";
});
Blade::directive("endscope", fn() => "<?php }); ?>");
Blade::directive('endscope', fn () => '<?php }); ?>');
}
}

View File

@ -6,9 +6,7 @@
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\{Arr, Carbon, Str};
use Illuminate\View\Component;
final class Table extends Component
@ -44,10 +42,8 @@ public function __construct(
// Remove closures from serialization
unset($this->rowDecoration, $this->cellDecoration, $this->headers);
// Serialize a unique ID for component tracking
$this->uuid = "table-" . md5(serialize($this)) . $id;
$this->uuid = 'table-'.md5(serialize($this)).$id;
// Restore closures
$this->rowDecoration = $rowDecoration;
@ -104,7 +100,7 @@ public function redirectLink(mixed $row): string
// Replace tokens with actual row values
$tokens->each(function (string $token) use ($row, &$link): void {
$link = Str::of($link)->replace("{" . $token . "}", data_get($row, $token))->toString();
$link = Str::of($link)->replace('{'.$token.'}', data_get($row, $token))->toString();
});
return $link;

View File

@ -3,8 +3,7 @@
declare(strict_types=1);
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Foundation\Configuration\{Exceptions, Middleware};
return Application::configure(basePath: dirname(__DIR__))
->withRouting(

View File

@ -3,22 +3,11 @@
declare(strict_types=1);
use Illuminate\Contracts\Support\Arrayable;
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
use Spatie\LaravelData\Casts\EnumCast;
use Spatie\LaravelData\Normalizers\ArrayableNormalizer;
use Spatie\LaravelData\Normalizers\ArrayNormalizer;
use Spatie\LaravelData\Normalizers\JsonNormalizer;
use Spatie\LaravelData\Normalizers\ModelNormalizer;
use Spatie\LaravelData\Normalizers\ObjectNormalizer;
use Spatie\LaravelData\RuleInferrers\AttributesRuleInferrer;
use Spatie\LaravelData\RuleInferrers\BuiltInTypesRuleInferrer;
use Spatie\LaravelData\RuleInferrers\NullableRuleInferrer;
use Spatie\LaravelData\RuleInferrers\RequiredRuleInferrer;
use Spatie\LaravelData\RuleInferrers\SometimesRuleInferrer;
use Spatie\LaravelData\Casts\{DateTimeInterfaceCast, EnumCast};
use Spatie\LaravelData\Normalizers\{ArrayNormalizer, ArrayableNormalizer, JsonNormalizer, ModelNormalizer, ObjectNormalizer};
use Spatie\LaravelData\RuleInferrers\{AttributesRuleInferrer, BuiltInTypesRuleInferrer, NullableRuleInferrer, RequiredRuleInferrer, SometimesRuleInferrer};
use Spatie\LaravelData\Support\Creation\ValidationStrategy;
use Spatie\LaravelData\Transformers\ArrayableTransformer;
use Spatie\LaravelData\Transformers\DateTimeInterfaceTransformer;
use Spatie\LaravelData\Transformers\EnumTransformer;
use Spatie\LaravelData\Transformers\{ArrayableTransformer, DateTimeInterfaceTransformer, EnumTransformer};
return [
/*
@ -26,36 +15,36 @@
* is an array, it will try to convert from the first format that works,
* and will serialize dates using the first format from the array.
*/
"date_format" => DATE_ATOM,
'date_format' => DATE_ATOM,
/*
* When transforming or casting dates, the following timezone will be used to
* convert the date to the correct timezone. If set to null no timezone will
* be passed.
*/
"date_timezone" => null,
'date_timezone' => null,
/*
* It is possible to enable certain features of the package, these would otherwise
* be breaking changes, and thus they are disabled by default. In the next major
* version of the package, these features will be enabled by default.
*/
"features" => [
"cast_and_transform_iterables" => false,
'features' => [
'cast_and_transform_iterables' => false,
/*
* When trying to set a computed property value, the package will throw an exception.
* You can disable this behaviour by setting this option to true, which will then just
* ignore the value being passed into the computed property and recalculate it.
*/
"ignore_exception_when_trying_to_set_computed_property_value" => false,
'ignore_exception_when_trying_to_set_computed_property_value' => false,
],
/*
* Global transformers will take complex types and transform them into simple
* types.
*/
"transformers" => [
'transformers' => [
DateTimeInterface::class => DateTimeInterfaceTransformer::class,
Arrayable::class => ArrayableTransformer::class,
BackedEnum::class => EnumTransformer::class,
@ -65,7 +54,7 @@
* Global casts will cast values into complex types when creating a data
* object from simple types.
*/
"casts" => [
'casts' => [
DateTimeInterface::class => DateTimeInterfaceCast::class,
BackedEnum::class => EnumCast::class,
// Enumerable::class => Spatie\LaravelData\Casts\EnumerableCast::class,
@ -76,7 +65,7 @@
* validation rules to properties of a data object based upon
* the type of the property.
*/
"rule_inferrers" => [
'rule_inferrers' => [
SometimesRuleInferrer::class,
NullableRuleInferrer::class,
RequiredRuleInferrer::class,
@ -89,7 +78,7 @@
* it cannot normalize the payload. The normalizers below are used for
* every data object, unless overridden in a specific data object class.
*/
"normalizers" => [
'normalizers' => [
ModelNormalizer::class,
// Spatie\LaravelData\Normalizers\FormRequestNormalizer::class,
ArrayableNormalizer::class,
@ -103,7 +92,7 @@
* this key can be set globally here for all data objects. You can pass in
* `null` if you want to disable wrapping.
*/
"wrap" => null,
'wrap' => null,
/*
* Adds a specific caster to the Symphony VarDumper component which hides
@ -111,7 +100,7 @@
* by `dump` or `dd`. Can be 'enabled', 'disabled' or 'development'
* which will only enable the caster locally.
*/
"var_dumper_caster_mode" => "development",
'var_dumper_caster_mode' => 'development',
/*
* It is possible to skip the PHP reflection analysis of data objects
@ -124,18 +113,18 @@
* in seconds if you want the cache to clear after a certain
* timeframe.
*/
"structure_caching" => [
"enabled" => true,
"directories" => [app_path("Data")],
"cache" => [
"store" => env("CACHE_STORE", env("CACHE_DRIVER", "file")),
"prefix" => "laravel-data",
"duration" => null,
'structure_caching' => [
'enabled' => true,
'directories' => [app_path('Data')],
'cache' => [
'store' => env('CACHE_STORE', env('CACHE_DRIVER', 'file')),
'prefix' => 'laravel-data',
'duration' => null,
],
"reflection_discovery" => [
"enabled" => true,
"base_path" => base_path(),
"root_namespace" => null,
'reflection_discovery' => [
'enabled' => true,
'base_path' => base_path(),
'root_namespace' => null,
],
],
@ -144,23 +133,23 @@
* method. By default, only when a request is passed the data is being validated. This
* behaviour can be changed to always validate or to completely disable validation.
*/
"validation_strategy" => ValidationStrategy::OnlyRequests->value,
'validation_strategy' => ValidationStrategy::OnlyRequests->value,
/*
* A data object can map the names of its properties when transforming (output) or when
* creating (input). By default, the package will not map any names. You can set a
* global strategy here, or override it on a specific data object.
*/
"name_mapping_strategy" => [
"input" => null,
"output" => null,
'name_mapping_strategy' => [
'input' => null,
'output' => null,
],
/*
* When using an invalid include, exclude, only or except partial, the package will
* throw an exception. You can disable this behaviour by setting this option to true.
*/
"ignore_invalid_partials" => false,
'ignore_invalid_partials' => false,
/*
* When transforming a nested chain of data objects, the package can end up in an infinite
@ -168,39 +157,39 @@
* set as a safety measure to prevent this from happening. When set to null, the
* package will not enforce a maximum depth.
*/
"max_transformation_depth" => null,
'max_transformation_depth' => null,
/*
* When the maximum transformation depth is reached, the package will throw an exception.
* You can disable this behaviour by setting this option to true which will return an
* empty array.
*/
"throw_when_max_transformation_depth_reached" => true,
'throw_when_max_transformation_depth_reached' => true,
/*
* When using the `make:data` command, the package will use these settings to generate
* the data classes. You can override these settings by passing options to the command.
*/
"commands" => [
'commands' => [
/*
* Provides default configuration for the `make:data` command. These settings can be overridden with options
* passed directly to the `make:data` command for generating single Data classes, or if not set they will
* automatically fall back to these defaults. See `php artisan make:data --help` for more information
*/
"make" => [
'make' => [
/*
* The default namespace for generated Data classes. This exists under the application's root namespace,
* so the default 'Data` will end up as '\App\Data', and generated Data classes will be placed in the
* app/Data/ folder. Data classes can live anywhere, but this is where `make:data` will put them.
*/
"namespace" => "Data",
'namespace' => 'Data',
/*
* This suffix will be appended to all data classes generated by make:data, so that they are less likely
* to conflict with other related classes, controllers or models with a similar name without resorting
* to adding an alias for the Data object. Set to a blank string (not null) to disable.
*/
"suffix" => "Data",
'suffix' => 'Data',
],
],
@ -209,7 +198,7 @@
* these synths will automatically handle the data objects and their
* properties when used in a Livewire component.
*/
"livewire" => [
"enable_synths" => true,
'livewire' => [
'enable_synths' => true,
],
];

View File

@ -2,9 +2,7 @@
declare(strict_types=1);
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
use Monolog\Handler\{NullHandler, StreamHandler, SyslogUdpHandler};
use Monolog\Processor\PsrLogMessageProcessor;
return [

View File

@ -30,7 +30,7 @@ public function definition(): array
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'password' => self::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,

View File

@ -6,7 +6,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
return new class() extends Migration
{
/**
* Run the migrations.
*/

View File

@ -6,7 +6,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
return new class() extends Migration
{
/**
* Run the migrations.
*/

View File

@ -6,7 +6,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
return new class() extends Migration
{
/**
* Run the migrations.
*/

View File

@ -6,7 +6,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
return new class() extends Migration
{
/**
* Run the migrations.
*/

View File

@ -1,21 +1,11 @@
{
"preset": "per",
"preset": "laravel",
"rules": {
"align_multiline_comment": true,
"array_indentation": true,
"array_syntax": true,
"blank_line_after_namespace": true,
"blank_line_after_opening_tag": true,
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
"concat_space": {
"spacing": "one"
},
"declare_parentheses": true,
"declare_strict_types": true,
"explicit_string_variable": true,
"final_class": true,
"fully_qualified_strict_types": true,
"group_import": true,
"single_import_per_statement": false,
"global_namespace_import": {
"import_classes": true,
"import_constants": true,
@ -23,14 +13,8 @@
},
"is_null": true,
"lambda_not_used_import": true,
"logical_operators": true,
"mb_str_functions": true,
"method_chaining_indentation": true,
"modernize_strpos": true,
"new_with_braces": true,
"no_empty_comment": true,
"not_operator_with_space": true,
"ordered_traits": true,
"protected_to_private": true,
"simplified_if_return": true,
"strict_comparison": true,
@ -38,7 +22,11 @@
"trim_array_spaces": true,
"use_arrow_functions": true,
"void_return": true,
"yoda_style": true,
"yoda_style": {
"equal": true,
"identical": true,
"less_and_greater": null
},
"array_push": true,
"assign_null_coalescing_to_coalesce_equal": true,
"explicit_indirect_variable": true,
@ -49,33 +37,21 @@
"no_superfluous_elseif": true,
"no_useless_else": true,
"nullable_type_declaration_for_default_null_value": true,
"ordered_imports": {
"sort_algorithm": "alpha"
"strict_param": true,
"date_time_immutable": true,
"mb_str_functions": true,
"logical_operators": true,
"ordered_interfaces": true,
"ordered_traits": true,
"php_unit_strict": true,
"phpdoc_align": {
"align": "vertical"
},
"ordered_class_elements": {
"order": [
"use_trait",
"case",
"constant",
"constant_public",
"constant_protected",
"constant_private",
"property_public",
"property_protected",
"property_private",
"construct",
"destruct",
"magic",
"phpunit",
"method_abstract",
"method_public_static",
"method_public",
"method_protected_static",
"method_protected",
"method_private_static",
"method_private"
],
"sort_algorithm": "none"
}
"phpdoc_separation": true,
"return_type_declaration": {
"space_before": "none"
},
"single_line_throw": false
}
}

View File

@ -1,21 +1,20 @@
<?php
use App\Data\Ui\ConnectedServices\ConnectedServiceCollectionData;
use App\Data\Ui\ConnectedServices\ConnectedServiceData;
use App\Data\Ui\ConnectedServices\ConnectedServicesData;
use App\Enums\ConnectionStatus;
use App\Enums\ConnectionTechTypes;
use Illuminate\Support\Collection;
use Livewire\Component;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\DataCollection;
new class extends Component {
public ConnectedServicesData $connectedServices;
#[DataCollectionOf(ConnectedServiceData::class)]
public DataCollection $connectedServices;
public function mount(): void
{
$this->connectedServices = new ConnectedServicesData(
services: new ConnectedServiceCollectionData([
$this->connectedServices = ConnectedServiceData::collect([
new ConnectedServiceData(
name: 'Microsoft Outlook',
icon: 'home',
@ -44,14 +43,13 @@ public function mount(): void
connectionService: 'Redmine',
status: ConnectionStatus::Error
),
])
);
], DataCollection::class);
}
};
?>
<div class="flex overflow-x-auto gap-x-4">
@foreach ($connectedServices->services as $service)
@foreach ($connectedServices as $service)
<x-shared.card class="min-w-60">
<div class="flex space-x-4">
<div class="bg-blue-200 p-4 rounded-lg flex items-center justify-center max-h-10">

View File

@ -1,7 +1,6 @@
<?php
use App\Data\Ui\ManageRoles\RoleData;
use App\Data\Ui\ManageRoles\ServiceData;
use App\Data\Ui\ManageRoles\{RoleData,ServiceData};
use App\Data\Ui\TableHeader;
use App\Data\Users\UserData;
use App\Enums\RolesStatus;

View File

@ -2,9 +2,7 @@
declare(strict_types=1);
use App\Livewire\Settings\Appearance;
use App\Livewire\Settings\Profile;
use App\Livewire\Settings\Security;
use App\Livewire\Settings\{Appearance, Profile, Security};
use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Features;

View File

@ -4,8 +4,7 @@
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\{Event, URL};
use Laravel\Fortify\Features;
beforeEach(function (): void {