Skip to content

Commit 109a2c6

Browse files
committed
fixing phpstan issues
1 parent 2b30342 commit 109a2c6

5 files changed

Lines changed: 45 additions & 22 deletions

File tree

subdomains/src/Filament/Components/Actions/SetSrvTargetAction.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ protected function setUp(): void
2929
->default(fn () => $node?->srv_target)
3030
->placeholder('play.example.com OR IPv4/IPv6 address')
3131
->helperText(trans('subdomains::strings.srv_target_confirmation'))
32-
- requireConfirmation()
33-
->rules(['nullable', 'string', 'regex:/^(?=.{1,253}$)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*$/']),
32+
->rules(['nullable', 'string', 'regex:/^(?=.{1,253}$)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*$/']),
3433
];
3534
});
3635

@@ -43,6 +42,6 @@ protected function setUp(): void
4342
->body(trans('subdomains::strings.notifications.srv_target_updated'))
4443
->warning()
4544
->send();
46-
})->requiresConfirmation()->modalIconColor('danger')->modalDescription(trans('subdomains::strings.srv_target_confirmation')->toString());
45+
})->requiresConfirmation()->modalIconColor('danger');
4746
}
4847
}

subdomains/src/Filament/Server/Resources/Subdomains/SubdomainResource.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public static function table(Table $table): Table
8080
->state(fn (Subdomain $subdomain) => $subdomain->getLabel()),
8181
TextColumn::make('record_type')
8282
->label(trans('subdomains::strings.record_type'))
83-
->icon(fn (Subdomain $subdomain) => $subdomain->srv_record && empty($subdomain->server?->node?->srv_target) ? 'tabler-alert-triangle' : null)
84-
->color(fn (Subdomain $subdomain) => $subdomain->srv_record && empty($subdomain->server?->node?->srv_target) ? 'danger' : null)
85-
->helperText(fn (Subdomain $subdomain) => $subdomain->srv_record && empty($subdomain->server?->node?->srv_target) ? trans('subdomains::strings.srv_target_missing') : null),
83+
->icon(fn (Subdomain $subdomain) => $subdomain->srv_record && empty($subdomain->server?->node->srv_target) ? 'tabler-alert-triangle' : null)
84+
->color(fn (Subdomain $subdomain) => $subdomain->srv_record && empty($subdomain->server?->node->srv_target) ? 'danger' : null)
85+
->tooltip(fn (Subdomain $subdomain) => $subdomain->srv_record && empty($subdomain->server?->node->srv_target) ? trans('subdomains::strings.srv_target_missing') : null),
8686
])
8787
->recordActions([
8888
EditAction::make()
@@ -111,15 +111,15 @@ public static function form(Schema $schema): Schema
111111
TextInput::make('name')
112112
->label(trans('subdomains::strings.name'))
113113
->required()
114-
->suffix(fn (callable $get) => CloudflareDomain::find($get('domain_id'))?->name)
114+
->suffix(fn (callable $get) => CloudflareDomain::find($get('domain_id'))->name)
115115
->unique(),
116116
Select::make('domain_id')
117117
->label(trans_choice('subdomains::strings.domain', 1))
118118
->disabledOn('edit')
119119
->required()
120120
->relationship('domain', 'name')
121121
->preload()
122-
->default(fn () => CloudflareDomain::first()?->id ?? null)
122+
->default(fn () => CloudflareDomain::first()->id ?? null)
123123
->searchable(),
124124
Toggle::make('srv_record')
125125
->label(trans('subdomains::strings.srv_record'))

subdomains/src/Models/Subdomain.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected static function boot(): void
5858
Notification::make()
5959
->success()
6060
->title(trans('subdomains::strings.notifications.cloudflare_record_created_title'))
61-
->body(trans('subdomains::strings.notifications.cloudflare_record_created', ['subdomain' => $model->name . '.' . ($model->domain?->name ?? 'unknown'), 'record_type' => $model->record_type]))
61+
->body(trans('subdomains::strings.notifications.cloudflare_record_created', ['subdomain' => $model->name . '.' . ($model->domain->name ?? 'unknown'), 'record_type' => $model->record_type]))
6262
->send();
6363

6464
return true;
@@ -73,7 +73,7 @@ protected static function boot(): void
7373
Notification::make()
7474
->success()
7575
->title(trans('subdomains::strings.notifications.cloudflare_record_updated_title'))
76-
->body(trans('subdomains::strings.notifications.cloudflare_record_updated', ['subdomain' => $model->name . '.' . ($model->domain?->name ?? 'unknown'), 'record_type' => $model->record_type]))
76+
->body(trans('subdomains::strings.notifications.cloudflare_record_updated', ['subdomain' => $model->name . '.' . ($model->domain->name ?? 'unknown'), 'record_type' => $model->record_type]))
7777
->send();
7878

7979
return true;
@@ -88,7 +88,7 @@ protected static function boot(): void
8888
Notification::make()
8989
->success()
9090
->title(trans('subdomains::strings.notifications.cloudflare_record_deleted_title'))
91-
->body(trans('subdomains::strings.notifications.cloudflare_record_deleted', ['subdomain' => $model->name . '.' . ($model->domain?->name ?? 'unknown')]))
91+
->body(trans('subdomains::strings.notifications.cloudflare_record_deleted', ['subdomain' => $model->name . '.' . ($model->domain->name ?? 'unknown')]))
9292
->send();
9393

9494
return true;
@@ -140,7 +140,7 @@ protected function upsertOnCloudflare(): bool
140140
Notification::make()
141141
->danger()
142142
->title(trans('subdomains::strings.notifications.cloudflare_missing_zone_title'))
143-
->body(trans('subdomains::strings.notifications.cloudflare_missing_zone', ['domain' => $this->domain?->name ?? 'unknown', 'subdomain' => $this->name . '.' . ($this->domain?->name ?? 'unknown')]))
143+
->body(trans('subdomains::strings.notifications.cloudflare_missing_zone', ['domain' => $this->domain->name ?? 'unknown', 'subdomain' => $this->name . '.' . ($this->domain->name ?? 'unknown')]))
144144
->send();
145145

146146
return false;
@@ -154,30 +154,30 @@ protected function upsertOnCloudflare(): bool
154154
Notification::make()
155155
->danger()
156156
->title(trans('subdomains::strings.notifications.cloudflare_missing_srv_port_title'))
157-
->body(trans('subdomains::strings.notifications.cloudflare_missing_srv_port', ['server' => $this->server?->name ?? 'unassigned']))
157+
->body(trans('subdomains::strings.notifications.cloudflare_missing_srv_port', ['server' => $this->server->name ?? 'unassigned']))
158158
->send();
159159

160160
return false;
161161
}
162162

163163
$serviceRecordType = ServiceRecordType::fromServer($this->server);
164164
if (!$serviceRecordType) {
165-
Log::warning('Unable to determine service record type for SRV record', ['server_id' => $this->server?->id, 'server' => $this->server?->name]);
165+
Log::warning('Unable to determine service record type for SRV record', ['server_id' => $this->server->id ?? 'unknown', 'server' => $this->server->name ?? 'unknown']);
166166
Notification::make()
167167
->danger()
168168
->title(trans('subdomains::strings.notifications.cloudflare_invalid_service_record_type_title'))
169-
->body(trans('subdomains::strings.notifications.cloudflare_invalid_service_record_type', ['subdomain' => $this->name . '.' . ($this->domain?->name ?? 'unknown')]))
169+
->body(trans('subdomains::strings.notifications.cloudflare_invalid_service_record_type', ['subdomain' => $this->name . '.' . ($this->domain->name ?? 'unknown')]))
170170
->send();
171171

172172
return false;
173173
}
174174

175-
if (empty($this->server?->node?->srv_target)) {
175+
if (empty($this->server?->node->srv_target)) {
176176
Log::warning('Node missing SRV target for SRV record', ['node_id' => $this->server->node?->id]);
177177
Notification::make()
178178
->danger()
179179
->title(trans('subdomains::strings.notifications.cloudflare_missing_srv_target_title'))
180-
->body(trans('subdomains::strings.notifications.cloudflare_missing_srv_target', ['node' => $this->server->node?->name ?? 'unknown']))
180+
->body(trans('subdomains::strings.notifications.cloudflare_missing_srv_target', ['node' => $this->server->node->name ?? 'unknown']))
181181
->send();
182182

183183
return false;
@@ -198,7 +198,7 @@ protected function upsertOnCloudflare(): bool
198198
Notification::make()
199199
->danger()
200200
->title(trans('subdomains::strings.notifications.cloudflare_upsert_failed_title'))
201-
->body(trans('subdomains::strings.notifications.cloudflare_upsert_failed', ['subdomain' => $this->name . '.' . ($this->domain?->name ?? 'unknown'), 'errors' => json_encode($result['errors'] ?? $result['body'] ?? [])]))
201+
->body(trans('subdomains::strings.notifications.cloudflare_upsert_failed', ['subdomain' => $this->name . '.' . ($this->domain->name ?? 'unknown'), 'errors' => json_encode($result['errors'] ?? $result['body'] ?? [])]))
202202
->send();
203203

204204
return false;

subdomains/src/Providers/SubdomainsPluginProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use App\Filament\Admin\Resources\Servers\ServerResource;
77
use App\Models\Role;
88
use App\Models\Server;
9-
use Boy132\Subdomains\Filament\Admin\Resources\Nodes\Pages\EditNode;
9+
use App\Filament\Admin\Resources\Nodes\Pages\EditNode;
1010
use Boy132\Subdomains\Filament\Components\Actions\SetSrvTargetAction;
11+
use Boy132\Subdomains\Filament\Admin\Resources\Servers\RelationManagers\SubdomainRelationManager;
1112
use Boy132\Subdomains\Models\Subdomain;
1213
use Illuminate\Support\Facades\Http;
1314
use Illuminate\Support\ServiceProvider;

subdomains/src/Services/CloudflareService.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ public function getZoneId(string $domainName): ?string
1717
}
1818

1919
try {
20+
// @phpstan-ignore staticMethod.notFound
2021
$response = Http::cloudflare()->get('zones', [
2122
'name' => $domainName,
2223
]);
2324
} catch (\Throwable $e) {
2425
Log::error('Cloudflare getZoneId request failed: ' . $e->getMessage(), ['domain' => $domainName]);
2526

26-
return ['success' => false, 'errors' => ['exception' => $e->getMessage()], 'status' => $e->getCode(), 'body' => $e->getTraceAsString()];
27+
return null;
2728
}
2829

2930
$body = $response->json();
@@ -36,9 +37,19 @@ public function getZoneId(string $domainName): ?string
3637
Log::warning('Cloudflare getZoneId returned errors', ['domain' => $domainName, 'status' => $response->status(), 'errors' => $body['errors']]);
3738
}
3839

39-
return ['success' => false, 'errors' => [], 'status' => $response->status(), 'body' => $body];
40+
return null;
4041
}
4142

43+
/**
44+
* @param string $zoneId
45+
* @param string $name
46+
* @param string $recordType
47+
* @param string $target
48+
* @param string|null $recordId
49+
* @param int|null $port
50+
*
51+
* @return array{success: bool, id: string|null, errors: array<string, mixed>, status: int, body: mixed|null}
52+
*/
4253
public function upsertDnsRecord(string $zoneId, string $name, string $recordType, string $target, ?string $recordId = null, ?int $port = null): array
4354
{
4455
if (empty($zoneId) || empty($name) || empty($recordType)) {
@@ -89,6 +100,7 @@ public function upsertDnsRecord(string $zoneId, string $name, string $recordType
89100

90101
try {
91102
if ($recordId) {
103+
// @phpstan-ignore staticMethod.notFound
92104
$response = Http::cloudflare()->put("zones/{$zoneId}/dns_records/{$recordId}", $payload);
93105
$parsed = $this->parseCloudflareHttpResponse($response);
94106

@@ -101,6 +113,7 @@ public function upsertDnsRecord(string $zoneId, string $name, string $recordType
101113
return $parsed;
102114
}
103115

116+
// @phpstan-ignore staticMethod.notFound
104117
$response = Http::cloudflare()->post("zones/{$zoneId}/dns_records", $payload);
105118
$parsed = $this->parseCloudflareHttpResponse($response);
106119

@@ -118,13 +131,19 @@ public function upsertDnsRecord(string $zoneId, string $name, string $recordType
118131
}
119132
}
120133

134+
/**
135+
* @param string $zoneId
136+
* @param string $recordId
137+
* @return array{success: bool, id: string|null, errors: array<string, mixed>, status: int, body: mixed|null}
138+
*/
121139
public function deleteDnsRecord(string $zoneId, string $recordId): array
122140
{
123141
if (empty($zoneId) || empty($recordId)) {
124142
return ['success' => false, 'errors' => ['missing_parameters' => true], 'status' => 0, 'body' => null];
125143
}
126144

127145
try {
146+
// @phpstan-ignore staticMethod.notFound
128147
$response = Http::cloudflare()->delete("zones/{$zoneId}/dns_records/{$recordId}");
129148

130149
$parsed = $this->parseCloudflareHttpResponse($response);
@@ -137,12 +156,16 @@ public function deleteDnsRecord(string $zoneId, string $recordId): array
137156

138157
return $parsed;
139158
} catch (\Throwable $e) {
140-
Log::error('Cloudflare delete exception: ' . $e->getMessage(), ['zone' => $zoneId, 'id' => $recordId, 'payload' => $payload, 'status' => $e->getCode()]);
159+
Log::error('Cloudflare delete exception: ' . $e->getMessage(), ['zone' => $zoneId, 'id' => $recordId, 'status' => $e->getCode()]);
141160

142161
return ['success' => false, 'errors' => ['exception' => $e->getMessage()], 'status' => $e->getCode(), 'body' => $e->getTraceAsString()];
143162
}
144163
}
145164

165+
/**
166+
* @param Response $response
167+
* @return array{success: bool, id: string|null, errors: array<string, mixed>, status: int, body: mixed|null}
168+
*/
146169
protected function parseCloudflareHttpResponse(Response $response): array
147170
{
148171
$status = $response->status();

0 commit comments

Comments
 (0)